O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  


NETWORKING HACK

Network connectivity/ server monitor
Modification of a script found originally in Unix Hints and Hacks. This script pings various servers and if it doesn't get a response, it emails it's findings, i.e. which box it can't connect to. I had one script running on site and one remotely from home. I found that my ISP's routers were dropping a lot of packets and causing false positives (false alarms). I added the mtr line to tell me if the routers between the two machines were the problem. Replace the reserved IP addresses with real onsite or remote server IP addresses. Same for the email addresses for the admin and pager. The c option for ping was initially 3, but I had to increase it to 10 for the remote script because my ISP's routers were dropping ICMP packets too frequently. With a minor modification, you can easily make this script a cron job.

Contributed by:
John Moore
[05/07/03 | Discuss (0) | Link to this hack]

#!/bin/sh HOSTS="192.168.1.1 192.168.1.2 192.168.2.2" for SYS in $HOSTS; do PING=`ping -c 10 -s 100 $SYS | grep received | awk -F, '{print $2}' | awk '{print $1}'` if [ $PING -eq 0 ]; then #echo "$SYS unreachable" | mail -s "PING FAILED" acct#@skytel.com echo "$SYS unreachable" | mail -s "PING FAILED" sysadmin@somewhere.net mtr -c 100 -p 576 -r $SYS | mail -s "mtr stats for $SYS" sysadmin@somewhere.net fi done

See also: Unix Hacks and Hints and www.ugu.com


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.