A ping detection alarm function code

Source: Internet
Author: User

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
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.