ITPub博客

首页 > Linux操作系统 > Linux操作系统 > [Shell] Ping host status

[Shell] Ping host status

原创 Linux操作系统 作者:tolilong 时间:2016-03-18 21:25:57 0 删除 编辑
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

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24237320/viewspace-2059751/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2010-07-13

  • 博文量
    406
  • 访问量
    1208686