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