当前位置: 移动技术网 > 网络运营>服务器>Linux > shell脚本编写ping包及arp的监控并发送短信功能

shell脚本编写ping包及arp的监控并发送短信功能

2017年12月08日  | 移动技术网网络运营  | 我要评论

下面给大家分享shell脚本编写ping包及arp的监控并发送短信功能,具体代码如下所示:

#!/bin/bash
now="`date +%y%m%d-%h:%m:%s`"
phones=15134567893
ip=10.100.8.78
gateway=10.100.30.1
#ping失误的短信内容
content1="host is failed"
#arp主机网关失误的短信内容
content2="gw is failed"
#ping日志路径
logfile="/tmp/ping`date "+%y%m%d-%h-%m-%s"`.log"
#ping对方主机100个包并将结果输出到日志
ping -c100 $ip &> $logfile
#用if,else语句判断是否ping通,
if [ "$?" == "0" ]; 
  then
    echo "$now $ip is ok">> $logfile
else
    echo "$now $ip is down">> $logfile &/usr/bin/curl -d "phones=$phones&content= $now $ip $content" "content-type: application/x-www-form-urlencoded;charset=utf-8" "http://短信网关:8080"
fi
#分隔符
echo "================================" >> $logfile
#arp自己网关
arp $gateway &>>$logfile
num=$(cat $logfile |grep eth0|wc -l)
  if [ "$num" == "0" ]; 
    then
     echo "$now $gateway is down">> $logfile &/usr/bin/curl -d "phones=$phones&content= $now $gateway $content1" "content-type: application/x-www-form-urlencoded;charset=utf-8" "http://短信网关:8080"
fi

以上所述是小编给大家介绍的shell脚本编写ping包及arp的监控并发送短信,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网