Up until the last few days, I was a member of the slower than molassis club. Doing work on the home LAN was no problem, but the second I stepped through the gateway into the outside world it was rough going. And while we were dialed up an awful lot, we weren't always online, so I needed a way to tell my primary box when a good time was to run rdate and fetchmail, and when not to. Not to mention, with a dail up modem came a random and dynamic IP address if I wanted/needed to get in from work. Hence the following bit of code. I should warn you, it's not beautiful. For starters, I probably should have used some variation of the Net:: modules, there were probably better ways to handle things, etc.. I kind of just got it far enough to be functional and then got the cable modem. For all you dial up users out there, perhaps this can be a starting point...?

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); } }

In reply to Salvation for Dial Up Users (with some awful Perl) by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.