#!/bin/bash
SERVERS="208.67.222.222 208.67.220.220"
LOG_FILE="/root/modem.log"
function ping_stuff() {
# takes a list of IPs/domain-names as an argument
got_a_response=1
for ip in $1; do
if ping -c1 -q $ip > /dev/null; then
got_a_response=0
fi
done
return $got_a_response
}
if ! ping_stuff "$SERVERS"; then
# If we can't ping anything wait a minute and try again
sleep 1m
# if the ping fails again restart the modem
if ! ping_stuff "$SERVERS"; then
dec2lpt 1
sleep 3
dec2lpt 0
echo "$(echo -n `date`) - Restarted Modem" >> $LOG_FILE
fi
fi