Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Most esteemed monks: I wanted to write a sort of "wrapper" script for my crontab that calls fetchmail to ping an external host before attempting to fetch the mail, since my cable network connectivity can often be quite flaky. When it's unreachable, my mailbox fills up with fetchmail error messages. So I decided to use the Net::Ping module, but it's not quite working as expected.
I wrote this simple script to test things:
#!/usr/bin/perl -w use strict; use Net::Ping; my $fetchmail = '/usr/local/bin/fetchmail'; my @fetchmail_args = ('-s', '-t', '60'); my $hostname = 'hostname'; # an external host my $timeout = 3; my $p = Net::Ping->new('udp', $timeout); if( $p->ping($hostname) ){ print "$hostname is alive.\n"; # exec($fetchmail, @fetchmail_args); }else{ print "$hostname is unreachable.\n"; }
Then within the if/else construct I would place an exec() call (to fetchmail with the desired parameters once I knew the ping portion was working correctly.

However, when putting the external hostname in $hostname, it always returns "unreachable", yet I can still use /bin/ping to reach it just fine. So I tried for a $hostname also 'localhost', '127.0.0.1', and also the local interface's IP address, '10.0.0.1'. But they also all return unreachable.

What am I doing wrong? It must be something quite simple... Thank you for your consideration.

--Kozz


In reply to Module Net-Ping by Kozz

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (6)
    As of 2014-08-23 04:39 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (172 votes), past polls