1.Shell脚本
[mon@oracle6 source]$ more mon_host_stat
#!/bin/bash
datetime=`date +"%Y/%m/%d %H:%M:%S"`
DATA=/home/mon/source/config/mon_host_stat.data
COUNT=4
LOG=/home/mon/data/mon_host_stat.log
echo -n "" > $LOG
cat $DATA | while read LINE
do
IP=`echo $LINE | awk '{print $1}'`
HOSTNAME=`echo $LINE | awk '{print $2}'`
RESULT=`ping $IP -c $COUNT | grep "packet loss" | awk '{print $6}' | sed 's/%//g'`
if [ $RESULT -gt 0 ];then
echo "$HOSTNAME $IP $RESULT% Lost Packet" >> $LOG
fi
done
if [ -s $LOG ];then
echo "$LOG Is not null"
cat $LOG | mutt -s "Ping Host Check Status" tolilong@163.com
else
echo "$LOG Is null"
fi
配置文件
[mon@oracle6 config]$ pwd
/home/mon/source/config
[mon@oracle6 config]$ more mon_host_stat.data
xxx.16.99.35 oracle6
xxx.16.99.19 oracle
xxx.16.99.20 xxxxxxx
xxx.168.169.120 standby
xxx.168.169.121 xxxxxxx1
xxx.168.169.122 xxxxxxx2
xxx.168.169.133 abcd
2.crontab job
[mon@oracle6 config]$ crontab -l
###############ping host check status############################
00,5,10,15,20,25,30,35,40,45,50,55 * * * * /home/mon/source/mon_host_stat > /dev/null 2>&1
[mon@oracle6 source]$ more mon_host_stat
#!/bin/bash
datetime=`date +"%Y/%m/%d %H:%M:%S"`
DATA=/home/mon/source/config/mon_host_stat.data
COUNT=4
LOG=/home/mon/data/mon_host_stat.log
echo -n "" > $LOG
cat $DATA | while read LINE
do
IP=`echo $LINE | awk '{print $1}'`
HOSTNAME=`echo $LINE | awk '{print $2}'`
RESULT=`ping $IP -c $COUNT | grep "packet loss" | awk '{print $6}' | sed 's/%//g'`
if [ $RESULT -gt 0 ];then
echo "$HOSTNAME $IP $RESULT% Lost Packet" >> $LOG
fi
done
if [ -s $LOG ];then
echo "$LOG Is not null"
cat $LOG | mutt -s "Ping Host Check Status" tolilong@163.com
else
echo "$LOG Is null"
fi
配置文件
[mon@oracle6 config]$ pwd
/home/mon/source/config
[mon@oracle6 config]$ more mon_host_stat.data
xxx.16.99.35 oracle6
xxx.16.99.19 oracle
xxx.16.99.20 xxxxxxx
xxx.168.169.120 standby
xxx.168.169.121 xxxxxxx1
xxx.168.169.122 xxxxxxx2
xxx.168.169.133 abcd
2.crontab job
[mon@oracle6 config]$ crontab -l
###############ping host check status############################
00,5,10,15,20,25,30,35,40,45,50,55 * * * * /home/mon/source/mon_host_stat > /dev/null 2>&1
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24237320/viewspace-2059751/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/24237320/viewspace-2059751/