1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来。
grep -v '/sbin/nologin' /etc/passwd|wc -l
grep -v '/sbin/nologin' /etc/passwd|cut -d':' -f1
2、查出用户UID最大值的用户名、UID及shell类型
cut -d':' -f1,3,7 /etc/passwd|sort -t':' -k2 -nr|head -n1
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
ss -nl|grep -Eo '([0-9]{1,3}\.){3}[0-9]'|sort|uniq -c
4、编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值
#!/bin/bash
df |grep -o "[0-9]\{1,2\}%"|tr -d '%'|sort -nr |head -n1
5、编写脚本 systeminfo.sh,显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小
#!/bin/bash
RED="echo -e \E[31m"
GREEN="\E[32m"
YELLOW="echo -e \E[33m"
BLUE="echo -e \E[34m"
END="\E[0m"
IP=\`ifconfig eth0|grep -Eo "(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])"|head -n1\`
CPU=\`lscpu|grep 'Model name'|cut -d':' -f2|tr -d ' '\`
MEM=\`free -h|grep 'Mem'|tr -s ' ' :|cut -d':' -f2\`
DISK=\`lsblk|grep 'disk'|tr -s ' ' :|cut -d':' -f5\`
$YELLOW-------------------systeminfo--------------------\$END
$RED 主机名:\$END \$GREEN \`hostname\` \$END
$RED IPv4地址:\$END \$GREEN \$IP \$END
$RED 操作系统版本:\$END \$GREEN \`cat /etc/redhat-release\` \$END
$RED 内核版本:\$END \$GREEN \`uname -r\` \$END
$RED CPU型号:\$END \$GREEN \$CPU \$END
$RED 内存大小:\$END \$GREEN \$MEM \$END
$RED 硬盘大小:\$END \$GREEN \$DISK \$END
$BLUE---------------------end----------------------------\$END
systeminfo.png