Linux學習-第五週

一、編寫腳本 createuser.sh,實現以下功能:使用一個用戶名作爲參數,若是 指定參數的用戶存在,就顯示其存在,不然添加之;顯示添加的用戶的id號等信息

腳本內容:
[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

三、查找/etc目錄下大於1M且類型爲普通文件的全部文件

find /etc -size +1M -type f |xargs du -shui

四、打包/etc/目錄下面全部conf結尾的文件,壓縮包名稱爲當天的時間,並拷到/usr/local/src目錄備份。

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

六、查找/etc目錄下至少有一類用戶沒有執行權限的文件

find /etc -type f -not -perm -111ip

相關文章
相關標籤/搜索