爲了方便平常運維寫的一段簡單腳本,用於集中獲取服務器操做系統、CPU、內存使用、負載、硬盤使用、網絡信息。bash
腳本比較簡單,就不解釋了,有興趣的朋友請自行查看。服務器
#!/bin/bash
#
#Name:system_info
#Ver:1.0
#Author:lykyl
#
#
#程序說明:
#獲取服務器基本信息腳本
#
echo '[OS Info]'
echo 'Host Name: '`uname -n`
echo 'OS: '`cat /etc/redhat-release`
echo 'Kernel: '`uname -r`
echo
echo '[CPU Info]'
echo 'CPU: physical '`grep "physical id" /proc/cpuinfo |uniq |wc -l`' cores'`grep "cpu cores" /proc/cpuinfo |uniq`
echo
echo '[System Info]'
echo `uptime | sed 's/^.*load/load/g'`
echo "Zombie:`ps aux |awk '{print $8,$2,$11}'|sed -n '/^Z/p'|wc -l`"
echo
echo '[Memory Info]'
echo `free -m |grep Mem|awk '{ print "total:"$2 "MB used:"$3 "MB free:"$4 "MB shared:"$5 "MB buffers:"$6 "MB cached:"$7 "MB" }'`
echo
echo '[Disk Info]'
echo -e "`df -h|sed '1d'|awk '/%/ { if ($6=="") {printf "%s\ttotal:%s\tused:%s\tUse%:%s\n",$5,$1,$2,$4 } else {printf "%s\ttotal:%s\tused:%s\tUse%:%s\n",$6,$2,$3,$5 } }'`"
echo
echo '[Net Info]'
echo 'IP: '`ifconfig |grep "inet addr:" |grep -v "127.0.0.1"|awk '{ print $2 }'|awk -F: '{print $2}'`
echo "netstat: `netstat -an|awk '/^tcp/ { ++s[$NF] } BEGIN {ORS=" "} END {for(a in s) print a,s[a]}'`"網絡