練習(xí)
1可婶、統(tǒng)計(jì)出/etc/passwd文件中其默認(rèn)shell為非/sbin/nologin的用戶個(gè)數(shù)滚停,并將用戶都顯示出來(lái)
cat /etc/passwd | grep -v '\/sbin\/nologin$' |wc -l && cat /etc/passwd | grep -v '\/sbin\/nologin$'| cut -d':' -f 1,7
1.png
2、查出用戶UID最大值的用戶名馋记、UID及shell類型
cat /etc/passwd | sort -nr -t':' -k3 | head -1 | cut -d':' -f 1,3,7 | tr ':' ' '
2.png
3助赞、統(tǒng)計(jì)當(dāng)前連接本機(jī)的每個(gè)遠(yuǎn)程主機(jī)IP的連接數(shù)熬拒,并按從大到小排序
ss -an | tr -s ' ' | cut -d' ' -f6 | sed -rn '/[0-9]+\:[0-9]+$/p' | cut -d':' -f1 | sort | uniq -c | sort -rn
3.png
4语御、編寫(xiě)腳本 createuser.sh峻贮,實(shí)現(xiàn)如下功能:使用一個(gè)用戶名做為參數(shù),如果 指定參數(shù)的用戶存在应闯,就顯示其存在纤控,否則添加之;顯示添加的用戶的id號(hào)等 信息
#!/bin/bash
read -p "please input a username:" username
if id -u $username > /dev/null 2>&1; then
echo “${username} is alread exit!”
else
useradd ${username} &&
id ${username}
fi
4.png
5、編寫(xiě)生成腳本基本格式的腳本碉纺,包括作者船万,聯(lián)系方式,版本惜辑,時(shí)間,描述等
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
if expand ("%:e") == 'sh'
call setline(1, "#!/bin/bash")
call setline(2, "#Author:ZHS")
call setline(3, "#Email:****@163.com")
call setline(4, "#Time:".strftime("%F %T"))
call setline(5, "#Name:".expand("%"))
call setline(6, "#Version:V1.0")
call setline(7, "#Description:This is a test description script.")
call setline(8, "")
endif
endfunc
5.png