#!/bin/bash # Copyright (c) 2002 Mark Suter # # This shell script will manually bounce the default gw's interface # using ifup/ifdown if the default gateway can't be pinged. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # $Id: force-link-up,v 1.2 2004/06/19 11:49:32 suter Exp $ ## Set our PATH and test for needed binaries ## Debian: sudo apt-get install iproute iputils-ping host export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin hash test ip perl ping ifup ifdown || ( echo $0: required tools not present 2>&1 ; exit 1 ) ## Get the default gateway's IP addresses and interface name eval $(ip route show | perl -ne '/default via (\S+) dev (\S+)/ and print "ip=$1\ndev=$2\n"') ## It's up or we bounce it (using ppp0 as a default) ( test \! -z "$ip" && ping -W 5 -c 1 $ip >/dev/null 2>&1 ) || ( ifdown --force ${dev:-ppp0} 2>&1 >/dev/null ; sleep 1 ; ifup ${dev:-ppp0} )