Copy Code code as follows:
#!/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 "'-----> Script starts ..." >>ping_log
For host_1 in ${host_[*]};d o
host=192.168.1. $host _1
echo "--------> Start detecting $host server communication is normal, ping times $count"
ping_result= ' ping $host-c $ping _count |tail-2 |head-1 '
#sleep 1
echo "--------> Server $host detection Completed"
#取成功条数
Succ_ping= ' echo ${ping_result:23:1} '
#取失败百分比
Loss_ping= ' echo ${ping_result:46:4} '
If [$succ _ping-eq $ping _count];then
echo "This test results----> Ping $host server is normal"
echo "' Date" +%y%m%d%h:%m:%s "'---> $host server ping detects normal" >>ping_log
Else
echo "The results of this test----> $host server packet loss phenomenon, packet loss rate: $loss _ping"
echo "' Date" +%y%m%d%h:%m:%s "'---> $host server has packet loss, packet loss rate: $loss _ping" >>ping_err_log
#插入短信表-smssend00
For called in ${telno[*]};d o
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 (), today (), ' 00:00:00 ', ' 23:59:59 ', null,null,null,0,1, ' Server Alarm!! $host the server detected a packet loss is present, loss rate: $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 "'-----> Script completed ..." >>ping_log
}