您现在的位置是:服务器ping监控脚本

服务器ping监控脚本

Linux 日期:2016-12-01点击:3383
[root@zzfwb src]# cat monitor_ping.sh
#!/bin/sh

#ping count
COUNT=30

#if lose% > max%
MAX=80

#nowtime
LogFileName=/var/ping/monitor_$(date "+%Y%m%d%H%M%S").log
HostFileName=/var/ping/host_$(date "+%Y%m%d%H%M%S").txt

#list_hosts
curl  http://api.zzfwb.com/monitor/list_hosts.php >  $HostFileName

for ipadd in `cat $HostFileName`
do
  timing=`date "+%Y-%m-%d %H:%M:%S"`
  PingFileName=/var/ping/ping_${ipadd}_$(date "+%Y%m%d%H%M%S").log
  ping -i 0.2 $ipadd -c $COUNT > $PingFileName
  losspag=`grep "packet loss" $PingFileName |awk '{print $6}' |sed 's/%//g'`
  FLAG=`grep "min/avg/max" $PingFileName -c`
  if [ $losspag -ge $MAX ] ;
  then
    STR=`echo -n "$timing|$ipadd|$losspag|$COUNT|down|$FLAG" | base64`
    echo "$timing|$ipadd|$losspag|$COUNT|down|$FLAG" >> $LogFileName
  else
    STR=`echo -n "$timing|$ipadd|$losspag|$COUNT|up|$FLAG" | base64`
    echo "$timing|$ipadd|$losspag|$COUNT|up|$FLAG" >> $LogFileName
  fi

 /usr/bin/curl  http://api.zzfwb.com/monitor/send_ping.php?str=$STR >> $LogFileName

 echo '' >>  $LogFileName
 echo '' >>  $LogFileName

done

cd /var/ping
find /var/ping -name "*.log" -ctime +1 -exec rm -f {} \;
标签: Shell Linux ping

站长简介

姓名:喻理
微信:yuli0927
邮箱:yuli0927@126.com
不懂业务的运维工程师不是一个好程序员。

分类

最新文章

热门文章