一個ping檢測警示函數代碼

來源:互聯網
上載者:User

複製代碼 代碼如下:#!/bin/bash
ping_monitor()
{
host_=(203 204 205 207 208 209 210 212 213 214 215 216 217 218 219 220 221)
ping_count=3
called=(13000000001 13000000002 13000000003)
calling=13000000000
callop=1310000000
#main------------------------------------------------------------
echo "`date "+%Y%m%d %H:%M:%S"`----->指令碼開始執行......">>ping_log
for host_1 in ${host_[*]};do
host=192.168.1.$host_1
echo "-------->開始檢測$host伺服器通迅是否正常,ping次數$count"
ping_result=`ping $host -c $ping_count |tail -2 |head -1`
#sleep 1
echo "-------->伺服器$host檢測已完成"
#取成功條數
succ_ping=`echo ${ping_result:23:1}`
#取失敗百分比
loss_ping=`echo ${ping_result:46:4}`
if [ $succ_ping -eq $ping_count ];then
echo "本次檢測結果---->$host伺服器ping檢測正常"
echo "`date "+%Y%m%d %H:%M:%S"`--->$host伺服器ping檢測正常" >>ping_log
else
echo "本次檢測結果---->$host伺服器有丟包現象,丟包率為:$loss_ping"
echo "`date "+%Y%m%d %H:%M:%S"`--->$host伺服器有丟包現象,丟包率為:$loss_ping" >>ping_err_log
#插入簡訊表—smssend00
for called in ${telno[*]};do
mysql -h$dbhost -u$dbuser -p$dbpass -D$dbbase <<GETRECODE
INSERT INTO $dbtable (servercode,smsservercode,groupid,priority,calling,called,payer,orderdatetime,senddatetime,effectstarttime,
effectendtime,effectstarttime2,effectendtime2,invaliddatetime,feevalue,iffee,message,hideflag,msgtype,smsfeetype,ifsmsreport,service
type,morelatetomtflag,reserve,optempid,optuserid,clientprogramtype,optcode,optip,remark)
VALUES
(2,2,1,0,'$calling','$called','$callop',Now(),Now(),'00:00:00','23:59:59',NULL,NULL,NULL,0,1,'伺服器警示!!$host伺服器檢測到有丟包現像,丟包率:$loss_ping',0,1,2,0,'2_2',NULL,NULL,1,668,1,3001,'192.168.1.182',NULL)
GETRECODE
done
fi
done
echo "`date "+%Y%m%d %H:%M:%S"`----->指令碼運行完畢......">>ping_log
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.