【shell】通过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
相关推荐
txj 2020-09-08
travelinrain 2020-07-27
higheels 2020-07-27
wq0 2020-07-18
Jieen 2020-07-08
luobotoutou 2020-06-16
屿刃 2020-06-14
TinyDolphin 2020-06-13
大老张学编程 2020-06-12
kenson 2020-06-08
PlayerL 2020-06-03
LeoHan 2020-05-31
wenjs00 2020-05-29
comeonxueRong 2020-05-17
furongwei 2020-05-04
BingGoGo技术 2020-04-07
wanggongzhen 2020-03-27
89284553 2020-03-23