日期:2014-05-16 浏览次数:20874 次
#!/bin/bash ######################################################################## #This scripts is checking your host system: the cpu ,i/o,mem,network, #processes stat. # vision 1.0 Bate # Write by skate #If you have some advise about it ,you can mail :810312zxg@163.com ######################################################################## cd /home/oracle/sh #make the local language is chinese #export LANG=zh_CN removedate=`date +%d` curdate=`date +%H` logdir=/home/oracle/sh/log logcpuuse=$logdir/cpuuse.log logcpuload=$logdir/cpuload.log logioload=$logdir/ioload.log lognetworkload=$logdir/networkload.log logsysprocess=$logdir/sysprocess.log logmemuse=$logdir/memuse.log lognetsession=$logdir/netsession.log ################################ #统计cpu的使用率信息 ################################ #判断文件是否存在 if [ -f $logcpuuse ] then #echo "logfile is exist !" if [ "$curdate" == "23" ] then date +"%D %r" >>$logcpuuse sar -u 2 1 |grep all |head -1 >> $logcpuuse else sar -u 2 1 |grep all |head -1 >> $logcpuuse fi else #touch $logfile date > $logcpuuse sar -u 2 2 | grep CPU >> $logcpuuse fi ############################### #统计cpu的负载信息 ############################### if [ -f $logcpuload ] then #echo "logfile is exist !" uptime >> $logcpuload else #touch $logfile date > $logcpuload uptime >> $logcpuload fi ############################## #磁盘io的负载的信息 ############################## if [ -f $logioload ] then date +"%D %r" >> $logioload iostat -xd 1 1 | sed -n '2,$p' >> $logioload else date +"%D %r" > $logioload iostat -xd 1 1 | sed -n '2,$p' >> $logioload fi ################################# #统计网络负载的信息 ################################ if [ -f $lognetworkload ] then date +"%D %r" >> $lognetworkload sar -n DEV 1 3| grep eth0 >> $lognetworkload else date +"%D %r" > $lognetworkload sar -n DEV 1 3|head -3 |tail -1 >> $lognetworkload sar -n DEV 1 3| grep eth0 >> $lognetworkload fi ################################### #统计系统进程总数信息 ################################### if [ -f $logsysprocess ] then date +"%D %r" >> $logsysprocess sysnum=`ps aux | wc -l` oranum=` ps -ef |awk '/ora/&&/dbticket/' |wc -l` echo "processes of system is: $sysnum" >> $logsysprocess echo "processes of oracle is: $oranum" >> $logsysprocess else date +"%D %r" > $logsysprocess sysnum=`ps aux | wc -l` oranum=` ps -ef |awk '/ora/&&/dbticket/' |wc -l` echo "processes of system is: $sysnum" >> $logsysprocess echo "processes of oracle is: $oranum" >> $logsysprocess fi ############################## #统计内存的信息 ############################## if [ -f $logmemuse ] then date +"%D %r" >> $logmemuse free |grep -1 Mem |head -n 2|tail -1 >> $logmemuse free | grep Swap >> $logmemuse else date +"%D %r" > $logmemuse free |grep -1 Mem |head -n 2 >> $logmemuse free | grep Swap >> $logmemuse fi ############################### #查看网络连接数,tcp协议 ############################### if [ -f $lognetsession ] then date +"%D %r" >> $lognetsession netstat -an | grep -E "^(tcp)" | cut -c 74- | sort | uniq -c | sort -n >> $lognetsession else date +"%D %r" >> $lognetsession netstat -an | grep -E "^(tcp)" | cut -c