1,统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数并将用户都显示出来
grep -v '/sbin/nologin$' /etc/passwd | cut -d ':' -f 1,7
2,查出用户UID最大的用户名,UID及shell类型
cat /etc/passwd | sort -t ':' -k 3 -nr | head -1 | cut -d ':' -f1,3,7
3,统计当前连接本机的每个远程IP的连接数,并按从大到小排序
ss -ntu | awk -F " *|:" '!/State/{rip[$(NF-2)]++};END{for(i in rip)print rip[i],i}' | sort -nr
4,编写脚本createuser.sh,实现如下功能:使用一个用户名作为参数,如果指定参数的用户名存在,就显示其存在,否则添加之,并显示其id号等信息
[root@mage01 ~]#cat createuser.sh
#!/bin/bash
if id $1 &> /dev/null ;then
echo "User $1 is exist"
else
useradd $1
getent passwd $1
fi
5,编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
[root@mage01 ~]#cat ~/.vimrc
set ignorecase
set cursorline
set autoindent
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: xxx")
call setline(5,"#QQ: xxx")
call setline(6,"#Date: ".strftime("%Y-%m-%d"))
call setline(7,"#FileName: ".expand("%"))
call setline(8,"#Version: 1.0")
call setline(9,"#Description: The test script")
call setline(10,"#Copyright (C): ".strftime("%Y")." All rights reserved")
call setline(11,"#****")
call setline(12,"")
endif
endfunc
autocmd BufNewFile * normal G