主機IP:10.100.8.79
主機網(wǎng)關(guān):10.100.8.1
對方主機IP:10.100.8.78
從本機ping對方IP,并使用arp工具對本機的網(wǎng)關(guān)進行解析
點擊(此處)折疊或打開
鳳岡ssl適用于網(wǎng)站、小程序/APP、API接口等需要進行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!
-
#!/bin/bash
-
NOW="`date +%Y%m%d-%H:%M:%S`"
-
PHONES=15134567893
-
IP=10.100.8.78
-
GATEWAY=10.100.30.1
-
#ping失誤的短信內(nèi)容
-
content1="host is failed"
-
#arp主機網(wǎng)關(guān)失誤的短信內(nèi)容
-
content2="GW is failed"
-
#ping日志路徑
-
LogFile="/tmp/ping`date "+%Y%m%d-%H-%M-%S"`.log"
-
#ping對方主機100個包并將結(jié)果輸出到日志
-
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://短信網(wǎng)關(guān):8080"
-
fi
-
#分隔符
-
echo "================================" >> $LogFile
-
#arp自己網(wǎng)關(guān)
-
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://短信網(wǎng)關(guān):8080"
-
fi
當(dāng)前標(biāo)題:【shell】通過shell編寫ping包及arp的監(jiān)控并發(fā)送短信
標(biāo)題URL:
http://weahome.cn/article/pgeige.html