1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来。
[root@centos7 ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
sssd:x:998:995:User for sssd:/:/sbin/nologin
libstoragemgmt:x:997:994:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
colord:x:996:993:User for colord:/var/lib/colord:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
gluster:x:995:992:GlusterFS daemons:/run/gluster:/sbin/nologin
saslauth:x:994:76:Saslauthd user:/run/saslauthd:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
setroubleshoot:x:993:990::/var/lib/setroubleshoot:/sbin/nologin
rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin
radvd:x:75:75:radvd user:/:/sbin/nologin
chrony:x:992:989::/var/lib/chrony:/sbin/nologin
qemu:x:107:107:qemu user:/:/sbin/nologin
unbound:x:991:988:Unbound DNS resolver:/etc/unbound:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
geoclue:x:990:986:User for geoclue:/var/lib/geoclue:/sbin/nologin
pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
saned:x:989:983:SANE scanner daemon user:/usr/share/sane:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
gnome-initial-setup:x:988:982::/run/gnome-initial-setup/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
wuchenyi:x:1000:1000:wuchenyi:/home/wuchenyi:/bin/bash
mageia:x:1100:1100::/home/linux:/bin/bash
ovirtagent:x:175:175:oVirt Guest Agent:/usr/share/ovirt-guest-agent:/sbin/nologin
显示个数及用户:
[root@centos7 ~]# cat /etc/passwd | cut -d: -f1,7 | grep -v sbin/nologin | cat -n
1 root:/bin/bash
2 sync:/bin/sync
3 shutdown:/sbin/shutdown
4 halt:/sbin/halt
5 wuchenyi:/bin/bash
6 mageia:/bin/bash
2、查出用户UID最大值的用户名、UID及shell类型
[root@centos7 ~]# cat /etc/passwd | sort -t: -k 4 -n -r | cut -d: -f1,3,7 | head -1
nfsnobody:65534:/sbin/nologin
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
[root@centos7 ~]# w | tr -s " " | cut -d" " -f3 | tr -d [:alpha:] | uniq -c | sort -rn
2
1 123.123.123.111
1 123.123.123.110
4、编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等 信息
#!/bin/bash
read -p "please input need create username:" name
id “$name &>” /dev/null
if [ $? -eq 0 ];then
echo "$name is exist"
else
useradd $name >/dev/null
echo "12345" | passwd --stdin $name > /dev/null
echo "$name is create successful"
getent passwd $name
fi
5、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
cat > /root/.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,"#Author: Chen")
call setline(4,"#QQ: 135******")
call setline(5,"#Date: ".strftime("%Y-%m-%d"))
call setline(6,"#FileName: ".expand("%"))
call setline(7,"#Version: v1.0")
call setline(8,"#Description:Learning ")
call setline(9,"#********************************************************************")
call setline(10,"")
endif
endfunc
autocmd BufNewFile * normal G
EOF