Linux小试牛刀
1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
[root@centos7data]#getent passwd | grep -v /sbin/login |uniq -c 1 root:x:0:0:root:/root:/bin/bash 1 bin:x:1:1:bin:/bin:/sbin/nologin 1 daemon:x:2:2:daemon:/sbin:/sbin/nologin 1 adm:x:3:4:adm:/var/adm:/sbin/nologin 1 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin 1 sync:x:5:0:sync:/sbin:/bin/sync 1 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown 1 halt:x:7:0:halt:/sbin:/sbin/halt 1 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin 1 operator:x:11:0:operator:/root:/sbin/nologin 1 games:x:12:100:games:/usr/games:/sbin/nologin 1 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin 1 nobody:x:99:99:Nobody:/:/sbin/nologin 1 systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin 1 dbus:x:81:81:System message bus:/:/sbin/nologin 1 polkitd:x:999:998:User for polkitd:/:/sbin/nologin 1 libstoragemgmt:x:998:995:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin 1 colord:x:997:994:User for colord:/var/lib/colord:/sbin/nologin 1 rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin 1 gluster:x:996:993:GlusterFS daemons:/run/gluster:/sbin/nologin 1 saslauth:x:995:76:Saslauthd user:/run/saslauthd:/sbin/nologin 1 abrt:x:173:173::/etc/abrt:/sbin/nologin 1 rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin 1 pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin 1 radvd:x:75:75:radvd user:/:/sbin/nologin 1 rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin 1 nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin 1 unbound:x:994:989:Unbound DNS resolver:/etc/unbound:/sbin/nologin 1 chrony:x:993:988::/var/lib/chrony:/sbin/nologin 1 qemu:x:107:107:qemu user:/:/sbin/nologin 1 tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin 1 usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin 1 geoclue:x:992:986:User for geoclue:/var/lib/geoclue:/sbin/nologin 1 ntp:x:38:38::/etc/ntp:/sbin/nologin 1 sssd:x:991:985:User for sssd:/:/sbin/nologin 1 setroubleshoot:x:990:984::/var/lib/setroubleshoot:/sbin/nologin 1 saned:x:989:983:SANE scanner daemon user:/usr/share/sane:/sbin/nologin 1 gdm:x:42:42::/var/lib/gdm:/sbin/nologin 1 gnome-initial-setup:x:988:982::/run/gnome-initial-setup/:/sbin/nologin 1 sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin 1 avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin 1 postfix:x:89:89::/var/spool/postfix:/sbin/nologin 1 tcpdump:x:72:72::/:/sbin/nologin 1 liu:x:1000:1000:liu:/home/liu:/bin/bash 1 apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin 1 dhcpd:x:177:177:DHCP server:/:/sbin/nologin 1 wang:x:1001:1001::/home/wang:/bin/bash
[root@centos7data]#getent passwd | grep -v /sbin/login |wc -l 47
2、查出用户UID最大值的用户名、UID及shell类型
[root@centos7scripts]#getent passwd |sort -t: -k3 -nr |head -n1 nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
[root@centos7data]#last | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' | uniq -c | sort -rn 7 192.168.34.100 4 192.168.34.1 2 192.168.34.1
4、编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等 信息
5、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等