[root@centos-6_5 awk]# cat system.sh #!/bin/bash #coding:utf-8 #author:fjj #date:2018.1.28 echo "取出UID大於200或root的用戶信息:" awk -F: '{if ($3 >= 200 || $1 == "root") print "info:" $0}' /etc/passwd echo echo "取出前3列以外的全部列:" awk -F: '{for (i=3;i<NF;i++) print $i}' /etc/passwd | head -n 5 echo echo "取出磁盤使用百分比:" df -h | sed -n '2p' | awk '{print $5}' | awk -F% '{print $1}' echo echo "取出eth0的ip:" echo $(ifconfig | grep eth0 -A 1 | sed -n '2p' | awk '{print $2}' | awk -F: '{print $2}') echo $(ifconfig | grep eth0 -A 1 | sed -n '$p' | awk -F: '{print $2,$3}' | awk '{print "IP:"$1,"子網掩碼:"$3}') echo $(/sbin/ip a | grep "eth0:" -A 2 | sed -n '$p' | awk '{print $2}' | awk -F'/' '{print "IP:"$1,"子網掩碼:"$2}') echo echo "顯示當前開放的端口號:" netstat -anltp | awk -F: '{ print $2}' | awk '{print $1}' | grep -v "^$" | sort -n | uniq #netstat -antulp | awk -F: '{print $2}' | awk '{print $1}' | sed '/^$/d' | sort -n | uniq echo echo "CPU負載:" #uptime | awk -F'average:' '{print $2}' uptime | awk -F': ' '{print $2}' uptime | awk -F'average: ' '{print $2}' echo echo "CPU的個數:" lscpu | grep "^CPU(s)" -w | awk '{print $2}' echo [root@centos-6_5 awk]# sh system.sh 取出UID大於200或root的用戶信息: info:root:x:0:0:root:/root:/bin/bash info:saslauth:x:499:76:"Saslauthd user":/var/empty/saslauth:/sbin/nologin info:dockerroot:x:498:498:Docker User:/var/lib/docker:/sbin/nologin 取出前3列以外的全部列: 0 0 root /root 1 取出磁盤使用百分比: 8 取出eth0的ip: 10.135.113.229 IP:10.135.113.229 子網掩碼:10.135.127.255 IP:10.135.113.229 子網掩碼:18 顯示當前開放的端口號: 22 25 42654 47772 CPU負載: 0.00, 0.00, 0.00 0.00, 0.00, 0.00 CPU的個數: 1