(1) 統計個數
[root@CentOS8 ~]#grep "/sbin/nologin" /etc/passwd |wc -l
(2) 顯示用戶
法一: grep "/sbin/nologin" /etc/passwd |cut -d: -f1
法二:sed -En '/\/sbin\/nologin/s#^([^:]+):.$#\1#p' /etc/passwdshell
[root@CentOS8 ~]#grep ":cat /etc/passwd|cut -d: -f3|sort -nr|head -n1
:" /etc/passwd |cut -d: -f1,3,7
nobody:65534:/sbin/nologinbash
ss -nt |tail -n+2|tr -s " " |cut -d" " -f5|cut -d: -f1 |uniq -c |sort -nr
或netstat -t |tail -n+3|tr -s " "|cut -d" " -f5 |cut -d: -f1|uniq -c |sort -nride
df |tail -n+2|sed -En 's#.[[:space:]]+([0-9]+)%.$#\1#p' |sort -nr|head -1
df |tail -n+2|tr -s " "|cut -d' ' -f5|cut -d% -f1|sort -nr|head -1
腳本disk.sh的內容
#!/bin/bash
df -h|tail -n+2|tr -s " "|cut -d' ' -f5|cut -d% -f1|sort -nr|head -1
#或 df |tail -n+2|sed -En 's#.[[:space:]]+([0-9]+)%.$#\1#p' |sort -nr|head -1
賦權限chmod +x disk.sh
執行腳本./disk.sh spa
[root@CentOS8 script]#cat systeminfo.sh
#!/bin/bash
RED="\E[1;31m"
GREEN="\E[1;32m"
END="\E[0m"
echo -e $GREEN----------------------Host systeminfo--------------------$END
echo -e "HOSTNAME: $REDhostname
$END"
echo -e "IPADDR: $REDifconfig|grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}'|head -n1
$END"
echo -e "OSVERSION: $REDcat /etc/redhat-release
$END"
echo -e "KERNEL: $REDuname -r
$END"
echo -e "CPU: $REDlscpu|grep 'Model name'|tr -s ' '|cut -d : -f2
$END"
echo -e "MEMORY: $REDfree -h|grep Mem|tr -s ' ' : |cut -d : -f2
$END"
echo -e "DISK: $REDlsblk |grep '^sd' |tr -s ' ' |cut -d " " -f1,4 -z
$END"
echo -e $GREEN---------------------------------------------------------$END操作系統