In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to use shell to write alarm control and recovery content. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.
The 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
#Send troubleshooting SMS notification--invoke insert_table
messages="$host server communications restored `date "+%Y%m%d %H:%M:%S"`"
echo "$messages" >>./ log/ping_err_recover.log
insert_table
else
echo "This detection result--->$host Server ping detection normal"
echo "`date "+%Y%m%d %H:%M:%S"`--->$host Server ping detected OK,ping count $ping_count, receive $succ_ping" >./ log/ping_log
fi
else
echo "This detection result--->$host server has packet loss phenomenon, packet loss rate is:$loss_ping"
messages="`date "+%Y%m%d %H:%M:%S"`--->$host Server has packet loss, packet loss rate:$loss_ping"
#Deal with the number of alarms, more than 2 times will not alarm
#format host a(alarm times)
#Number of times alarms have occurred plus 1
echo "Alert server is $host"
if [ -f ./ alarm_file/alarm_$host ];then
#Take the current alarm 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 "Do not send SMS more than 2 times"
echo "`date "+%Y%m%d %H:%M:%S"`--->$host Server has packet loss phenomenon, received $succ_ping, packet loss rate:$loss_ping, more than two times will not be sent. " >>./ log/ping_err_log
else
#No more than 2 calls to insert_table function to send SMS
echo "Not more than 2 times"
echo "`date "+%Y%m%d %H:%M:%S"`--->$host Server has packet loss, received $succ_ping, packet loss rate:$loss_ping">>./ log/ping_err_log
insert_table
fi
else
The first alarm
echo "First alarm"
echo "$host 1" >./ alarm_file/alarm_$host
insert_table
echo "`date "+%Y%m%d %H:%M:%S"`--->$host Server has packet loss, received $succ_ping, packet loss rate:$loss_ping" >>./ log/ping_err_log
fi
fi
done
Thank you for reading! About "how to use shell to write alarm times control and recovery" this article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.