[Sussex] Run on net start

John Crowhurst fyremoon at fyremoon.net
Fri Feb 14 13:43:01 UTC 2003


> Thanks for the pointer John,
>
> Looks like a good place for it.
>
> The wish list would have a script be something that could actually
> monitor the interface to see if the route to the 'big wide world' was
> open...
>
> mmmm....now how could I script that.... ????

My router supports SNMP, so I have mrtg watching the traffic going in and
out on a 10 minute basis.

I wrote a simple ping script as a keepalive/connection re-enabler that
pings their DNS once a minute to make sure that the line is routable.

Simple stuff is usually the easiest. I wrote mine in perl, but its easy to
port to a different language, YMMV:

#!/usr/bin/perl

use Net::Ping;
use Expect;
$host="their.dns.server";
$p = Net::Ping->new("icmp");
if ($p->ping($host)) {
  print "Line is UP\n";
} else {
  print "Line is DOWN, restart router\n";
  $router="router.ip.address";
  $telnet=Expect->spawn("telnet $router");
  $telnet->expect(30,"ssword: ") || die "Not connected";
  print $telnet "router_password\r";
  print $telnet "ppp 1 disable\r";
  sleep 1;
  print $telnet "ppp 1 enable\r";
  sleep 1;
  print $telnet "@close\r";
  $telnet->hard_close();
}

The DSL router I have requires a telnet connection to it, and a simple ppp
1 disable & ppp 1 enable for it to kick the routing back into gear (hence
the need for the expect module)

--
John






More information about the Sussex mailing list