DSL watchdog script
I’m going to start posting a bunch of my ‘cheap hack’ UNIX tricks that I’ve picked up over the years. This first one is a DSL watchdog script.
How many times have you gone on vacation to find your DSL has burped, requiring a power cycle of your DSL modem, and leaving your home boxes (and email) stranded? If only you could train your cats to hit the power switch. Until then this script should work.
The script runs out of cron every 10 minutes, and checks to see if a few “always up” web sites are pingable. If they’re all down then it will assume there’s a problem with your DSL modem and power cycle the modem via an X10 lamp module. I have it also ping one host that’s on my ISP’s network to help differentiate problems where they lost connectivity to the world.
The hardware consists of an X10 transmit serial donglethat goes on the back of your home server and a lamp module that powers the DSL modem. I got mine as part of the $5 X10 Firecracker Kit years ago. Looks like they’re now$40.
Since X10 uses radio signals there’s a chance that my neighbor will be able to turn off my DSL modem. If that happens it’ll come back on within 10 minutes when the script runs. As with all X10 hardware, this is a calculated risk.
#!/bin/sh
# DSL Watchdog - Joe Gross
# Set this to be a reliable pingable host on your ISP's network
NEARHOST="www.speakeasy.net"
# Who gets notifications of resets
ADDR="root"
# Serial port of X10 dongle
XSERIAL="/dev/cuad0"
# X10 group for power outlet
XGROUP="O"
# X10 device for power outlet
XDEV="1"
DEBUG=0
PING="/sbin/ping"
FARHOST="www.google.com www.yahoo.com www.akamai.net"
HOSTLIST="$NEARHOST $FARHOST"
OFF="/usr/local/bin/br -x $XSERIAL -r 5 -c $XGROUP -f $XDEV"
ON="/usr/local/bin/br -x $XSERIAL -r 5 -c $XGROUP -n $XDEV"
DOWN=1
for i in $HOSTLIST
do
if [ $DEBUG -eq 1 ]; then echo “pinging $i”; fi
$PING -c 1 $i > /dev/null 2>&1
if [ $? -eq 0 ]
then
if [ $DEBUG -eq 1 ]; then echo “$i up”; fi
DOWN=0
fi
done
if [ $DOWN -eq 1 ]
then
echo “DSL reset: `date`” | mail -s “DSL reset: `date`” $ADDR
$OFF
sleep 60
$ON
fi
November 15th, 2007 at 4:20 am
[...] read more | digg story [...]