Shell write alarm number control and recovery sample code _linux shell

Source: Internet
Author: User
I am also a novice, write a bit old-fashioned, right when practicing, for beginners friends reference it.
Copy Code code as follows:

#!/bin/bash
If [$SUCC _ping-gt $ ((ping_count-1))];then
If [F./alarm_file/alarm_$host];then
Rm-rf./alarm_file/alarm_$host
#发送故障消除短信通知--Call insert_table
messages= "$host Server newsletter resumes normal ' date ' +%y%m%d%h:%m:%s '"
echo "$messages" >>./log/ping_err_recover.log
Insert_table
Else
echo "This test results----> Ping $host server is normal"
echo "' Date" +%y%m%d%h:%m:%s "'---> $host server ping detect normal, ping times $ping_count, receive $succ_ping" >>./log/ping_log
Fi
Else
echo "The results of this test----> $host server packet loss phenomenon, packet loss rate: $loss _ping"
messages= "' Date" +%y%m%d%h:%m:%s "'---> $host server packet loss, packet loss rate: $loss _ping"
#对警次数进行处理, more than 2 times will not alarm
#格式host A (number of alarms)
#已经出现告警的次数加1
echo "Alarm server is $host"
If [F./alarm_file/alarm_$host];then
#取出当前的告警次数并加1
A= ' awk ' {print$2} './alarm_file/alarm_$host '
b=$ (($a + 1))
echo "$host $b" >./alarm_file/alarm_$host
Alarm_count= ' awk ' {print$2} './alarm_file/alarm_$host '
If [$alarm _count-gt $sms _count];then
echo "does not send text messages more than 2 times"
echo "' Date" +%y%m%d%h:%m:%s "'---> $host server packet loss, receive $succ_ping, packet loss rate: $loss _ping, more than two times not sent. ">>./log/ping_err_log
Else
#未超过2次调用insert_table函数发送短信
echo "not more than 2 times"
echo "' Date" +%y%m%d%h:%m:%s "'---> $host server has lost packet phenomenon, receive $succ_ping, packet loss rate is: $loss _ping" >>./log/ping_err_log
Insert_table
Fi
Else
#第一次告警
echo "First Alarm"
echo "$host 1" >./alarm_file/alarm_$host
Insert_table
echo "' Date" +%y%m%d%h:%m:%s "'---> $host server has lost packet phenomenon, receive $succ_ping, packet loss rate is: $loss _ping" >>./log/ping_err_log
Fi
Fi
Done
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.