第四周

1、統(tǒng)計(jì)出/etc/passwd文件中其默認(rèn)shell為非/sbin/nologin的用戶個(gè)數(shù),并將用戶都顯示出來

1.grep -v "/sbin/nologin" /etc/passwd | cut -d: -f 1

2、查出用戶UID最大值的用戶名、UID及shell類型

sort -t ":" -n -k3 /etc/passwd |tail -1 | cut -d: -f1,3,7

3、統(tǒng)計(jì)當(dāng)前連接本機(jī)的每個(gè)遠(yuǎn)程主機(jī)IP的連接數(shù),并按照從大到小排序


1.第一步 基本實(shí)現(xiàn);ss -nt | tr -s " " | cut -d " " -f5 | cut -d ":" -f1 | uniq -c | sort -nr

2.第二步:過濾掉表頭解決方案

ss -nt | grep [[:digit:]] | tr -s " " | cut -d " " -f5 | cut -d ":" -f1 | uniq -c | sort -nr


netstat -nt | grep [[:digit:]] | tr -s " " | cut -d " " -f5 | cut -d ":" -f1 | uniq -c | sort -nr

4、編寫腳本

createuser.sh,?實(shí)現(xiàn)如下功能:?使用一個(gè)用戶名作為參數(shù),如果指定參數(shù)的用戶存在,就顯示其存在,否則添加之,顯示添加的用戶的id號(hào)等信息

#!/bin/bash

if [ $# -eq 0 ];then

? ? echo "user a argument after the script name"

? ? exit

elif [ $# -gt 1 ];then

? ? echo " one arg is requed ,but $# arg was suplled"

? ? exit

fi

if id -u $1 &> /dev/null;then

? ? echo "the user has exits,peng refirm it"

else

? ? useradd $1 && echo "user $1 is created,`id $1`"

fi



5、編寫生成腳本基本格式的腳本,包括作者,聯(lián)系方式,版本,時(shí)間,描述等

=====================================================================

set tabstop=4

set softtabstop=4

set shiftwidth=4

set expandtab

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? ? ? ? ? ? ? ? ? czq")

? ? call setline(5,"#phone? ? ? ? ? ? ? ? ? 177**********")

? ? cal? setline(6,"#Date? ? ? ? ? ? ? ? ? ".strftime("%Y-%m-%d"))

? ? endif

endfunc

autocmd BufNewFile * normal G

===================================================================================

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容