~drscream

Router, check the internet connection

Currently i've some problems with my router. The reconnect only work sometimes... . So i've started to write a small bash script, to check that connection. The script run every hour and start a reconnection if no pppoe connection is available.

#!/bin/bash
#--------------------------------------------------------------------
# $Id: checkIConnect,v 0.1 2008/02/11 17:17:26 drscream Exp $
# Copyright 2008 Frubar Network (drscream@frubar.net)
#--------------------------------------------------------------------

##
## main
##
errors=0
ns_ip=$(cat /etc/resolv.conf | sed 's/nameserver //g' | head -n 1)

## device check
$(/sbin/ip a s dev ppp0 > /dev/null 2>&1)
if [ $? -gt 0 ]; then
        echo "ERROR: Device not found!"
        let errors=$errors+1
fi

## nameserver, ping check
$(ping -c 4 $ns_ip > /dev/null 2>&1)
if [ $? -gt 0 ]; then
        echo "ERROR: Ping doesn't work!"
        let errors=$errors+1
fi

echo "Code: $errors"

if [ $errors -gt 0 ]; then
        echo "INFO: reconnect internet"
        /opt/fruky/bin/pppoe-restart
fi

Send your comment by mail.