Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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', '', and also the local interface's IP address, ''. But they also all return unreachable.

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


In reply to Module Net-Ping by Kozz

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, 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
  • 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (8)
    As of 2018-01-18 15:59 GMT
    Find Nodes?
      Voting Booth?
      How did you see in the new year?

      Results (212 votes). Check out past polls.