Quick Walkthrough: The idea was (if my own train of logic is too chaotic), to check to see if the ppp0 adaptor had an IP address associated with it. If it didn't, we weren't online and needed to drop any legacy temp files lying around. If it did, the first thing to do was to pull out the IP address and then compare it to our last temp file. The reason for this was that unless I set my cron job to run every minute (and even then), it was possible that we might have gotten disconnected and reconnected between checks. This way, it makes sure not only that the temp files exist, but that they contain the same info. If so, cool, we run any tasks we want to. If not, we update the temp file and send it to some external mail account. Why 2 temp files? I originally used the ONLINE file for other scripts to check against before running.
OK, enough babble, the code...
#!/usr/bin/perl $mail_to = 'SOME_ADDRESS@yahoo.com'; $tmp_file = '/tmp/ppp_status_report'; $ONLINE = '/tmp/ONLINE'; @ppp_status = `ifconfig ppp0`; #Grab the dynamic IP address if (defined(@ppp_status)) { @ppp_status[1] =~ /(addr\:[\S+]{4,15})/; $ppp_line = $1; if ( -f $tmp_file ) { open(TMP,"$tmpfile"); $line_tmp = <TMP>; close(TMP); if ($ppp_line == $line_tmp) {next;} else { open(TMP,">$tmp_file"); print TMP $ppp_line; close(TMP); + open(TMP,">$ONLINE"); + close(TMP); system ("mail -s \"PPP Address for MYB +OX\" $mail_to \<$tmp_file"); } + } else { open(TMP,">$tmp_file"); print TMP $ppp_line; close(TMP); open(TMP,">$ONLINE"); close(TMP); system ("mail -s \"PPP Addr +ess for MYBOX\" $mail_to \<$tmp_file"); } system("/usr/bin/fetchmail"); } else { if ( -f $ONLINE) { unlink($ONLINE); unlink($tmp_file); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Salvation for Dial Up Users (with some awful Perl)
by sparkyichi (Deacon) on Jan 21, 2002 at 13:48 UTC | |
by z3d (Scribe) on Jan 21, 2002 at 18:16 UTC |