shell脚本编写ping包及arp的监控并发送短信功能
下面给大家分享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
相关推荐
huha 2020-10-16
laisean 2020-11-11
大牛牛 2020-10-30
firefaith 2020-10-30
liguojia 2020-10-20
wangzhaotongalex 2020-10-20
以梦为马不负韶华 2020-10-20
JohnYork 2020-10-16
Julyth 2020-10-16
applecarelte 2020-10-16
laisean 2020-09-27
flycappuccino 2020-09-27
liguojia 2020-09-27
wangzhaotongalex 2020-09-22
流年浅滩 2020-10-23
liujianhua 2020-10-22
woaimeinuo 2020-10-21
tufeiax 2020-09-03
laisean 2020-09-01
vvu 2020-09-16
libao 2020-09-16
Yyqingmofeige 2020-08-18
zhushixia 2020-08-17