一、統計出/etc/passwd文件中其默認shell爲非/sbin/nologin的用戶個數,並將用戶都顯示出來shell
[23:20:02 root@centos7_6 data]# getent passwd |grep -v nologin |wc -l 6 [23:20:17 root@centos7_6 data]# [23:20:32 root@centos7_6 data]# [23:20:33 root@centos7_6 data]# getent passwd |grep -v nologin |cut -d: -f1 root sync shutdown halt jiangjingqun jiang [23:20:50 root@centos7_6 data]#
思路:
1)統計非/sbin/nologin的用戶個數,想到用grep -v參數,反向選擇;而後配合wc -l參數來統計個數;
2)要顯示用戶,使用cut命令,取出第一列centos
二、查出用戶UID最大值的用戶名、UID及shell類型bash
[23:29:23 root@centos7_6 data]# getent passwd |sort -t: -k3 -n |cut -d: -f1,3,7 |tail -1 nfsnobody:65534:/sbin/nologin [23:29:28 root@centos7_6 data]#
思路:
1)要查有UID、用戶名及shell,確定是passwd文件;
2)要找UID最大值,就先排個序,因而就用sort,以:號分列,-t:,UID在第3列,-k3,按數字排序-n
3)用cut按需分別把表明:用戶名、UID、shell類型的一、三、7列找出來
4)UID最大值的會排到最後,因而tail -1;ide
三、統計當前鏈接本機的每一個遠程主機IP的鏈接數,並按從大到小排序centos7
[14:14:19 root@localhost ~]#netstat -nt |awk '{print $5}' |grep [0-9] |sort -t: -k5 -nr 192.169.1.11:53277 192.169.1.102:40738 192.169.1.102:30700
四、編寫腳本 createuser.sh,實現以下功能:使用一個用戶名作爲參數,若是 指定參數的用戶存在,就顯示其存在,不然添加之;顯示添加的用戶的id號等 信息code
#!/bin/bash ######################################### #author:jiangjingqun #Date:2020-07-01 #FileName:createuser #Description:建立用戶,建立前判斷是否存在 ######################################## set -e set -u if [ $# -eq 0 ];then echo "Usage:Please Input user name" exit elif id $1 &>/dev/nul echo "user $1 exist!" exit else echo "start creat user $1" useradd $1 echo "user $1 create successd!" id $1 fi
五、編寫生成腳本基本格式的腳本,包括做者,聯繫方式,版本,時間,描述等orm
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: jiangjingqun") call setline(5,"#Date: ".strftime("%Y-%m-%d")) call setline(6,"#FileName: ".expand("%")) call setline(7,"#Description: The test script") call setline(8,"#Copyright (C): ".strftime("%Y")." All rights reserved") call setline(9,"############################################################################") call setline(12,"") endif endfunc autocmd BufNewFile * normal G