Solaris linux 系統監控指令碼

wangzhensheng發表於2007-04-23

#!/bin/sh
# Solaris system_monitor
#. /.profile
day=`date +%m%d%Y`
file="/var/log/system/sysinfo$day"
if [ -f $file ]; then
echo "ok">/dev/null

[@more@]

#!/bin/sh
# Solaris system_monitor
#. /.profile
day=`date +%m%d%Y`
file="/var/log/system/sysinfo$day"
if [ -f $file ]; then
echo "ok">/dev/null
else
echo " date cpu mem swap load average oracle sessions">>$file
echo " user system idle free free 1 5 15">>$file
echo "">>$file
fi
time=`date '+%m%d %H:%M:%S '`
load=`uptime |grep load|sed s/,//g|awk '{printf"%10s %6s %6s", $10,$11,$12}'`
#cpu=`vmstat |grep -v [cpu][swap]|awk '{printf "%8s %6s %9s", $20,$21,$22}'`
cpu=`vmstat 1 2 | sed -n '$p' |awk '{printf "%8s %6s %9s", $20,$21,$22}'`
real=`vmstat |grep -v [cpu][swap]|awk '{printf "%12s %10s",$5,$4}'`
httpd_number=`ps -ef|grep httpd|grep -v grep|wc -l|awk '{printf "%9d",$1}'`
oracle_number=`ps -ef|grep "LOCAL="|grep -v grep|wc -l|awk '{printf "%9d",$1}'`
echo "$timet$cpu$real$load$oracle_number" >>$file

========================================='

#!/bin/sh
# linux system_monitor
day=`date +%m%d%Y`
file="/var/log/system/sysinfo$day"
if [ -f $file ]; then
echo "ok">/dev/null
else
echo " date cpu mem load average sessions">>$file
echo " user system idle free 1 5 15">>$file
echo "">>$file
fi
time=`date '+%m%d %H:%M:%S '`
load=`uptime |grep load|sed s/,//g|awk '{printf"%10s %6s %6s", $8,$9,$10}'`
cpu=`vmstat 1 2 | sed -n '$p' |awk '{printf "%8s %6s %9s", $13,$14,$15}'`
real=`vmstat |grep -v [cpu][swap]|awk '{printf "%12s",$4}'`
httpd_number=`ps -ef|grep httpd|grep -v grep|wc -l|awk '{printf "%9d",$1}'`
app_number=`ps -ef |grep "java"|grep -v grep | wc -l`
oracle_number=`ps -ef|grep '/db/mysql/bin/mysqld' |grep -v grep|wc -l|awk '{printf "%9d",$1}'`
echo "$time $cpu$real$load$httpd_number+$app_number+$oracle_number" >>$file

============================================

root.cron
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /var/log/system/system_monitor&

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8806316/viewspace-912060/,如需轉載,請註明出處,否則將追究法律責任。

相關文章