Copy codeThe Code is 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 "'-----> start executing the script..."> ping_log
For host_1 in $ {host _ [*]}; do
Host = 192.168.1. $ host_1
Echo "--------> start to check if $ 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"
# Number of successful entries
Succ_ping = 'echo $ {ping_result: 23: 1 }'
# Percentage of Failures
Loss_ping = 'echo $ {ping_result: 46: 4 }'
If [$ succ_ping-eq $ ping_count]; then
Echo "the detection result ----> $ host server ping detection is normal"
Echo "'date" + % Y % m % d % H: % M: % S "'---> $ host server ping check normal"> ping_log
Else
Echo "This detection result ----> $ the host server has packet loss. The packet loss rate is: $ loss_ping"
Echo "'date" + % Y % m % d % H: % M: % S "'---> $ the host server suffers packet loss. The packet loss rate is: $ loss_ping"> ping_err_log
# Insert text message table-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
(, '$ Calling',' $ called', '$ callop', Now (), Now (), '00: 00: 00', '23: 59: 59', NULL, 0, 1, 'server alert !! $ The host server detects a packet loss image. Packet Loss Rate: $ loss_ping ', 1,668, 192, '2 _ 2', NULL, NULL. 168.1.182 ', NULL)
GETRECODE
Done
Fi
Done
Echo "'date" + % Y % m % d % H: % M: % S "'-----> the script has been run..."> ping_log
}