Shell-written alarm count control and recovery sample code

Source: Internet
Author: User
Tags server resume

I am also a newbie. I am a little old-fashioned. I am a good trainer. It is a reference for beginners. Copy codeThe Code is 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
# Sending a Fault Elimination Short Message notification -- calling insert_table
Messages = "$ host server resume normal 'date" + % Y % m % d % H: % M: % S "'"
Echo "$ messages">./log/ping_err_recover.log
Insert_table
Else
Echo "the detection result ----> $ host server ping detection is normal"
Echo "'date" + % Y % m % d % H: % M: % S "'---> $ host server ping check normal, ping times $ ping_count, receive $ succ_ping ">>. /log/ping_log
Fi
Else
Echo "This detection result ----> $ the host server has packet loss. The packet loss rate is: $ loss_ping"
Messages = "'date" + % Y % m % d % H: % M: % S "'---> $ the host server has packet loss. The packet loss rate is $ loss_ping"
# Handle the number of alerts. If the number of alerts exceeds 2, no alert is triggered.
# Host a (number of alerts)
# Increase the number of alerts by 1
Echo "the alarm server is $ host"
If [-f./alarm_file/alarm _ $ host]; then
# Retrieve the current Alert Count and Add 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 "no text message is sent more than twice"
Echo "'date" + % Y % m % d % H: % M: % S "'---> $ the host server receives $ succ_ping due to packet loss. The packet loss rate is: $ loss_ping. If it exceeds the limit, it is not sent again. ">./Log/ping_err_log
Else
# No more than two calls to the insert_table function to send text messages
Echo "no more than 2 times"
Echo "'date" + % Y % m % d % H: % M: % S "'---> $ the host server receives $ succ_ping due to packet loss. The packet loss rate is: $ loss_ping ">>. /log/ping_err_log
Insert_table
Fi
Else
# First Alert
Echo "first alarm"
Echo "$ host 1">./alarm_file/alarm _ $ host
Insert_table
Echo "'date" + % Y % m % d % H: % M: % S "'---> $ the host server receives $ succ_ping due to packet loss. The 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.