N43-第四周作业


1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来

cat /etc/passwd |grep -vc nologin

 
 
 

2、查出用户UID最大值的用户名、UID及shell类型

sort -t: -nr -k3 /etc/passwd|cut -d: -f1,3,7|head -1

 
 
 

3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序

w -h|tr -s " "|cut -d " " -f3|sort|uniq -c|sort -nr

 
 
 

4、编写脚本createuser.sh,实现如下功能:使用一个用户名做为参数,如果指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等信息

#!/bin/bash
read -p "please input your name :" name
[  -z $name ] && {
    
     echo "please input your name !" ; exit 10; }   #判断空
id $name &>/dev/null && {
    
     echo "user $name already exists"; exit 20; }   #判断用户存在
useradd $name &>/dev/null && {
    
     echo "$name is created"; echo -e `id $name`; exit 30; }   #判断用户不存在及操作

 
 
 

5、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等

vim ~/.vimrc

autocmd BufNewFile *.sh exec ":call SetTitle()"

func SetTitle()
        if expand("%:e")=='sh'
                call setline(1,"#!/bin/bash")
                call setline(2,"#")
                call setline(3,"#*************************************")
                call setline(4,"#author:                        Blurry")
				call setline(5,"QQ                          1010101010")
				call setline(6,"version:                           1.0")
                call setline(7,"#date:           ".strftime("%Y-%m-%d"))
                call setline(8,"#description:                     test")
                call setline(9,"#*************************************")

endif

endfunc

猜你喜欢

转载自blog.csdn.net/qq_42669579/article/details/113756282