I had a similar requirement when my cable ISP switched to DHCP. Once, when the lease on my IP address expired, the system (RH Linux) requested a renewal from the DHCP server. When it was unable to access the server (ISP problems), it completely shut down eth1. Also, when the IP address changes, ntpd stops functioning and has to be restarted. So I wrote the following cron script (keepalive.pl) to stay connected and keep ntpd alive:
#!/usr/bin/perl
use strict;
my $lastip;
if (open IP, '</home/phil/usr/cron/lastip.dat') {
$lastip = <IP>;
chomp $lastip;
close IP
} else {
print "**keepalive.pl** File 'lastip.dat' cannot be opened to read
+: $!"
}
if (`netstat -i` =~ /eth1.*?inet addr:(\d+\.\d+\.\d+\.\d+)/s) {
if ($1 ne $lastip) {
print "**keepalive.pl**\n\n".`/etc/init.d/ntpd restart`;
if (open IP, '>/home/phil/usr/cron/lastip.dat') {
print IP "$1\n";
close IP
} else {
print "**keepalive.pl** File 'lastip.dat' cannot be opened
+ to write: $!"
}
}
} else {
print "**keepalive.pl**\n\n".`/etc/init.d/network restart`
}
The script runs every five minutes. In the event that eth1 has been dropped, it restarts network, then on the next go 'round restarts nptd if the IP has changed. Maybe there will be something of value in there for you.
There's also a companion cron script (ddclient, a free perl script I downloaded) that keeps separate tabs on my IP address and keeps my dyndns entry up-to-date. ddclient uses a remote IP echoing server to obtain the address -- but, of course, fails when eth1 is killed.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.