1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
[19:48:01 root@centos7 ~]#grep .*/sbin/nologin.* /etc/passwd | cut -d: -f1
bin
daemon
adm
lp
mail
operator
games
ftp
nobody
systemd-network
dbus
polkitd
sssd
libstoragemgmt
colord
rpc
gluster
saslauth
abrt
setroubleshoot
rtkit
radvd
chrony
qemu
unbound
ntp
tss
usbmuxd
geoclue
pulse
gdm
saned
rpcuser
nfsnobody
gnome-initial-setup
sshd
avahi
postfix
tcpdump
[19:49:06 root@centos7 ~]#grep .*/sbin/nologin.* /etc/passwd | cut -d: -f1 | wc -l
39
2、查出用户UID最大值的用户名、UID及shell类型
[19:56:58 root@centos7 ~]#cat /etc/passwd | cut -d: -f1,3,7| sort -t : -k 2 -nr | head -1
nfsnobody:65534:/sbin/nologin
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
[20:11:45 root@centos7 ~]#netstat -nt |tr -s " " | cut -d " " -f 5 | egrep -o "[0-9.]{7,15}" | uniq -c | sort -nr
1 192.168.23.1
4、编写脚本createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等信息
脚本如下:
#!/bin/bash
#
#********************************************************************
#Author: ye
#Date: 2020-07-05
#FileName: createuser.sh
#Description: The test script
#Copyright (C): 2020 All rights reserved
#********************************************************************
read -p "please input the username: " NAME
`id $NAME &>/dev/null` && echo "The username exist!" || (useradd $NAME;echo "The user is created,the uid is `grep $NAME /etc/passwd | cut -d: -f3`")
执行结果如下:
[20:44:13 root@centos7 scripts]#bash createuser.sh
please input the username: user1
The user is created,the uid is 1001
[20:45:30 root@centos7 scripts]#bash createuser.sh
please input the username: user1
The username exist!
5、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
在家目录下编写.vimrc
文件,内容如下,即可使vim编写文件就是脚本基本格式。
set tabstop=4
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: ye")
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(10,"")
endif
endfunc
autocmd BufNewFile * normal G