A ping detection alarm function Code _linux Shell

Source: Internet
Author: User
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
}
Related Article

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.