第四周作業(yè)_20200629
?1、統計出/etc/passwd文件中其默認shell為非/sbin/nologin的用戶個數,并將用戶都顯示出來
?cat /etc/passwd | grep -v "sbin/nologin" | wc -l cat /etc/passwd | grep -v "sbin/nologin" | cut -d: -f1
?2、查出用戶UID最大值的用戶名、UID及shell類型
cat /etc/passwd | sort -t: -k3 -n | tail -1 | cut -d: -f1,3,7
3、統計當前連接本機的每個遠程主機IP的連接數,并按照從大到小排序
netstat -tn | grep "ESTABLISHED" | tr -s " " : | cut -d: -f4 | sort | uniq -c| sort -nr
4、編寫腳本createuser.sh, 實現如下功能: 使用一個用戶名作為參數,如果指定參數的用戶存在,就顯示其存在,否則添加之,顯示添加的用戶的id號等信息
[ $# -eq 0] && { echo "Please type the username " ; exit 2; }
id $1 &> /dev/null
if [ $? -eq 0 ] ; then
?????? echo "$1 has exist."
else?
?????? useradd $1 &> /dev/null && id $1
?fi
5、編寫生成腳本基本格式的腳本,包括作者,聯系方式,版本,時間,描述等
cat >> ~/.vimrc << EOF
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: lili")
??????? ??? call setline(5,"#QQ: 67557775")
??????????? call setline(6,"#Date: ".strftime("%Y-%m-%d"))
????????????call setline(7,"#FileName: ".expand("%"))
??????????? call setline(8,"#URL: http://www.itdecent.cn/u/47e8a5eb702b"
??????????? call setline(9,"#Description: The test script")
??????????? call setline(10,"#Copyright (C): ".strftime("%Y")." All right reserved")
??????????? ?call setline(11,"#************************************************************************************")
????????????? call setline(12," ")
?????????????? end if
endfunc
autocmd BufNewFile * normal G