How to implement a ping detection alarm function
This article mainly introduces how to achieve a ping detection alarm function, the article introduces in great detail, has a certain reference value, interested friends must read it!
The code is as follows:
#! / bin/bash
Ping_monitor ()
{
Host_= (203 204 205 207 208 209 210 212 213 214 215 216 217 218 219 220 221)
Ping_count=3
Called= (13000000001 130000002 130000003)
Calling=13000000000
Callop=1310000000
# main
Echo "`date" +% Y%m%d% H:%M:%S "`- > script starts execution." > > ping_log
For host_1 in ${host_ [*]}; do
Host=192.168.1.$host_1
Echo "- > start to check whether the communication of $host server is normal, and the number of ping times $count"
Ping_result= `ping $host-c $ping_count | tail-2 | head-1`
# sleep 1
Echo "- > Server $host detection completed"
# take the number of successful messages
Succ_ping= `echo ${ping_result:23:1} `
# take the percentage of failure
Loss_ping= `echo ${ping_result:46:4} `
If [$succ_ping-eq $ping_count]; then
Echo "this test result-> $host server ping test is normal"
Echo "`date" +% Y%m%d% H:%M:%S "`--> $host server ping detection is normal" > > ping_log
Else
Echo "results of this test-> $host server has lost packets, and the packet loss rate is: $loss_ping"
Echo "`date" +% Y%m%d% H:%M:%S "`--> $host server has lost packets. The packet loss rate is $loss_ping" > > ping_err_log.
# insert SMS list-smssend00
For called in ${telno [*]}; do
Mysql-h$dbhost-u$dbuser-p$dbpass-D$dbbase > ping_log
}
The above is all the contents of the article "how to implement a ping detection alarm function". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!