All pastes #915406 Raw Edit

Miscellany

public text v1 · immutable
#915406 ·published 2008-02-23 19:51 UTC
rendered paste body
#!/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