[[email protected]_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
[[email protected]_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
原文地址:http://blog.51cto.com/19941018/2066494