How to realize the shell of ping Discovery packet drop alarm
This article mainly shows you "how to achieve the shell of ping discovery and swap alarm", which is easy to understand and clear. I hope it can help you solve your doubts. Here, let me lead you to study and learn "how to realize the shell of ping discovery and swap alarm".
The code is as follows:
#! / bin/bash
PING= `which ping`
DATE= `date +% Y% m% d% H% M`
TAIL= `which tail`
LOG=./ping$DATE.log
HOSTS= "selboo.com.cn 221.130.191.97"
COUNT=200
For myHost in $HOSTS
Do
Count=$ (ping-c $COUNT $myHost | grep 'loss' | awk-Flowers' {print $3}'| awk-F "%"'{print $1}')
If [$count-ge 10]; then
/ bin/echo selboo | mutt-s "$myHost pingispacketloss > 10% $DATE" root@selboo.com.cn
Fi
Done
Exit 0
Copy the above to add ping.sh to crontab and let it run once every 10 minutes, and the email program is mutt.
The following is a supplement:
Linux's and solaris's are not the same!
The code is as follows:
#! / bin/sh
PingConf='/opt/monitor/newIp'
# File where the log will be stored
LogDir='/opt/monitor/newLog'
# Define the interval time
INTERVAL='10'
# Define the alarm process
# # #
Proc_main ()
{
While read IpAddress
Do
# ingore any hash signs
Case $IpAddress in
# *)
*)
Ping-w 20$ IpAddress-c 5 > errtmp$$
# ping $IpAddress-c 10 > errtmp$$
If [$? = 0]; then
Rm errtmp$$
Else
Rm errtmp$$
ErrTime= `date +% Y/%m/%d/%H:%M:% s`
# echo "$ErrTime": "" $IpAddress "" cann't be connected "> > $LogDir
Echo "$ErrTime": "" $IpAddress "" cann't be connected
"> > $LogDir
Sleep 1
Cp / opt/monitor/newLog / opt/OV/www/htdocs/PingLog/new.html
Sleep 1
# mail-s "$IpAddress" Cantreach-c my email