第四周作業

1、 統計出/etc/passwd文件中其默認shell爲非/sbin/nologin的用戶個數,並將用戶都顯示出來
getent passwd|cut -d':' -f1,7|grep -v /sbin/nologin|uniq -c
第四周作業
2、查出用戶UID最大值的用戶名、UID及shell類型
cat /etc/passwd|cut -d':' -f1,3,7|sort -t: -k2 -nr|head -n1
第四周作業
3、統計當前連接本機的每個遠程主機IP的連接數,並按從大到小排序
netstat -nt|tr -s ' ' ':'|cut -d':' -f6|grep '[0-9]'|sort|uniq -c|sort -nr
第四周作業
4、編寫腳本 createuser.sh,實現如下功能:使用一個用戶名做爲參數,如果 指定參數的用戶存在,就顯示其存在,否則添加之;顯示添加的用戶的id號等 信息
[ $# -eq 0 ] && echo "Usage:basename $0 USERNAME " && exit 0
id $1 &> /dev/null && echo "user $1 is exist" && exit 0
useradd $1 &> /dev/null && echo "user $1 is created" && echo "id $1" || { echo " Error! " ; exit 0; }
第四周作業
第四周作業

5、編寫生成腳本基本格式的腳本,包括作者,聯繫方式,版本,時間,描述等

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: changyu")
call setline(5,"#QQ: 1258620503")
call setline(6,"#Date: ".strftime("%Y-%m-%d"))
call setline(7,"#FileName: ".expand("%"))
call setline(8,"#Description: The test script")
call setline(9,"#Copyright (C): ".strftime("%Y")." All rights reserved")
call setline(10,"#****")
call setline(11,"")
endif
endfunc
autocmd BufNewFile * normal G
第四周作業

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章