腳本內容:
[root@CentOS8 script]#vim createuser.sh
#!/bin/bash
##############################################
#File Name: createuser.sh
#Version: V1.0
#Author: LiRui
#Created Time: 2020-12-28 10:55:42
#Description: The test script
#############################################
USER=$1
if [ -n "$USER" ];then
if id "$USER" &>/dev/null;then
echo "$USER is exit"
else
useradd $USER &>/dev/null && echo "add $USER" && id $USER
fi
else
echo "請輸入用戶名!"
fivim
執行結果:
[root@CentOS8 script]#./createuser.sh xiaoming 已經存在的用戶做爲參數
xiaoming is exit
[root@CentOS8 script]#./createuser.sh xiaohua 不存在的用戶做爲參數
add xiaohua
uid=1008(xiaohua) gid=1012(xiaohua) groups=1012(xiaohua)
[root@CentOS8 script]#./createuser.sh 沒有帶參數
請輸入用戶名!bash
在root用戶家目錄/root下,建立.vimrc文件,內容以下:
[root@CentOS8 ~]#vim .vimrc
set cul
"在Shell腳本開頭自動增長解釋器及做者等版權信息"
autocmd BufNewFile .sh exec ":call SetTitle()"
func SetTitle()
if expand("%:e") == 'sh'
call setline(1, "#!/bin/bash")
call setline(2, "##############################################")
call setline(3, "#File Name: ".expand("%"))
call setline(4, "#Version: V1.0")
call setline(5, "#Author: LiRui")
call setline(6, "#Created Time: ".strftime("%F %T"))
call setline(7, "#Description: The test script")
call setline(8, "##############################################")
call setline(9, "")
endif
endfunc
"新建文件後,自動定位到文件末尾"
autocmd BufNewFile normal Gide
find /etc -size +1M -type f |xargs du -shui
find /etc -size +1M -type f |xargs tar cf /data/test/date +%F
&>/dev/null && cp /data/test/date +%F
/usr/local/src code
find / ( -nouser -o -nogroup ) -atime -7orm
find /etc -type f -not -perm -111ip