- #!/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, the Else statement determines whether the ping pass,
- 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-ty Pe:application/x-www-form-urlencoded;charset=utf-8 "" http:/SMS Gateway 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 $content 1" "Content-type:application/x-www-form-urlencoded;charset=utf-8" "http:/SMS Gateway 8080"
- Fi
Shell writes ping packets and ARP monitoring and sends text messages through the shell