grep -v ‘/sbin/nologin‘ /etc/passwd | cut -d: -f 1
grep -v ‘/sbin/nologin‘ /etc/passwd | cut -d: -f 1 | wc -l
2、查出用户UID最大值的用户名、UID及shell类型
cat /etc/passwd | cut -d: -f1,3,7 | sort -t ":" -k 2 -rn | head -1
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
ss -nt | grep -v State | tr -s " " : | cut -d: -f6 | sort | uniq -c | sort -rn
4、编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值
[root@centos8 scripts]# cat disk.sh
#!/bin/bash
LIST_DISK_USERD=`df | grep ‘^/dev‘ | tr -s ‘ ‘ | cut -d " " -f 6,5 | sort -t% -k1 -nr`
echo "$LIST_DISK_USERD"
5、编写脚本 systeminfo.sh,显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小
[root@centos8 scripts]# cat systeminfo.sh
#!/bin/bash
RED="\033[1;31m"
GREEN="\033[1;32m"
END="\033[0m"
echo -e "$GREEN---------------------------------- Host systeminfo------------------------------$END"
echo -e "HOSTNAME: $RED `hostname` $END"
echo -e "IPADDR: $RED `ifconfig ens33 | egrep -o ‘([0-9]{1,3}\.){3}[0-9]{1,3}‘ | head -n1` $END"
echo -e "OSVERSION: $RED `cat /etc/system-release` $END"
echo -e "KERNEL: $RED `uname -r` $END"
echo -e "CPU: $RED `lscpu | grep ‘Model name‘ |tr -s ‘ ‘ | cut -d: -f2` $END"
echo -e "MEMORY: $RED `free -h|grep Mem|tr -s ‘ ‘ : |cut -d : -f2` $END"
echo -e "DISK: $RED `lsblk | grep ‘^sda‘ | tr -s ‘ ‘ : | cut -d : -f 1,5` $END"
echo -e "$GREEN--------------------------------------------------------------------------------$END"