In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.