1、统计出/etc/passwd文件中默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
getent passwd|grep -v "/sbin/nologin"|cut -d: -f1
2、查出用户UID最大值的用户名、UID以及shell类型
sort -t ":" -k 3 -nr /etc/passwd|cut -d: -f1,3,7
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
ss -ss -n|grep "^ESTAB"|tr -s " " :|cut -d: -f6|uniq -c|sort -nr
4、编写脚本createuser.sh,实现如下功能:
传递一个用户名参数,如果指定参数的用户存在,就显示其存再,否则添加并显示添加的用户id号等信息
[root@centos7 ~]# cat createuser.sh
#!/bin/bash
[ $# -eq 0 ] && { echo "Usage: `basename $0` username";exit 1; }
if /usr/bin/id $1 &> /dev/null;then
echo "User $1 is exists"
else
/usr/sbin/useradd $1 &> /dev/null
echo "User $1 is create,the user information is as follows:"
/usr/bin/id $1
fi
5、编写生成脚本基本格式的脚本,包括作者、联系方式、版本、时间、描述等
[root@contos7 ~]# cat .vimrc
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
if expand("%:e") == 'sh'
call setline(1,"#!/bin/bash")
call setline(2,"#*************************************************************")
call setline(3,"#Author: sun")
call setline(4,"#Date: ".strftime("%Y-%m-%d"))
call setline(5,"#FileName: ".expand("%"))
call setline(6,"#*************************************************************")
call setline(7,"")
endif
endfunc
autocmd BufNewFile * normal G
[root@contos7 ~]# vim test.sh
[root@contos7 ~]# cat test.sh
#!/bin/bash
#*************************************************************
#Author: sunb
#Date: 2020-03-11
#FileName: test.sh
#*************************************************************
echo "Hello world!"