Copy Code code 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
Todo
count=$ (ping-c $COUNT $myHost | grep ' loss ' | awk-f ', ' {print $} ' | awk-f '% ' ' {print '} ')
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 content for ping.sh to join the crontab to let it run in 10 minutes, where the email program for Mutt
The following are supplementary:
Linux and Solaris are not the same!
Copy Code code as follows:
#!/bin/sh
pingconf= '/opt/monitor/newip '
#File where the log would be stored
Logdir= '/opt/monitor/newlog '
#Define The interval time
Interval= ' 10 '
#Define the alarm process
########################################################
Proc_main ()
{
While read IPAddress
Todo
#ingore any hash signs
Case $IpAddress in
#*);;
*)
Ping-w $IpAddress-C 5 >errtmp$$
# ping $IpAddress-C >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 </dev/null
Play-v 50/opt/monitor/123.au
Fi
Esac
Done < $PingConf
}
##########################################################
# Execute the Proc_main function every the specified time INTERVAL
While ["1"-eq "1"]
Todo
# Execute the Proc_main function
Proc_main
# Suspend execution for INTERVAL seconds
Sleep $INTERVAL
Done