------------恢复内容开始------------
1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
awk -F: '{shells[$NF]++;if($NF == "/sbin/nogin"){print $1,$NF}}END{for(i in shells){print i,shells[i]}}' /etc/passwd
2、查出用户UID最大值的用户名、UID及shell类型
getent passwd|sort -t: -k3 -rn|head -1|cut -d: -f1,3,7
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
netstat -nt ls s
4、编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等 信息
1 #!/bin/bash
2 #
3 #********************************************************************
4 #Author: 小汤圆
5 #:
6 #Date: 2019-11-25
7 #FileName: createuser.sh
8 #URL: 暂无
9 #Description: The test script
10 #Copyright (C): 2019 All rights reserved
11 #QQ Address 2382990774
12 #**************************************************************
13 useradd $1 &> /dev/null
14 if [ $? -eq 0 ] ;then
15 echo "user $1 is created"
16 id $1
17 else
18 echo "user exits already or no argument "
19 fi
~
5、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
1 set ignorecase
2 set cursorline
3 set autoindent
4 autocmd BufNewFile *.sh exec ":call SetTitle()"
5 func SetTitle()
6 if expand("%:e") == 'sh'
7 call setline(1,"#!/bin/bash")
8 call setline(2,"#")
9 call setline(3,"#********************************************************************")
10 call setline(4,"#Author: 小汤圆")
11 call setline(5,"#: ")
12 call setline(6,"#Date: ".strftime("%Y-%m-%d"))
13 call setline(7,"#FileName: ".expand("%"))
14 call setline(8,"#URL: 暂无")
15 call setline(9,"#Description: The test script")
16 call setline(10,"#Copyright (C): ".strftime("%Y")." All rights reserved")
17 call setline(11,"#QQ Address 2382990774")
18 call setline(12,"#**************************************************************")
19 call setline(13,"")
20 endif
21 endfunc
22 autocmd BufNewFile * normal G
~