Here's the script in its entirety (running on ActiveState Perl 5.6.1 on an NT4 box, if it matters):

use strict; use Getopt::Long; use Net::Ping; use Time::HiRes qw( gettimeofday tv_interval ); #vars my %args; my @hosts; #option defaults my $timeout = 3; my $yawn = 2; my $infile = 'pinger_time_hostlist.txt'; my $outfile = 'pinger_time_results.txt'; my $help; my $ok = GetOptions ( 'wait=i' => \$timeout, 'sleep=i' => \$yawn, 'inputfile=s' => \$infile, 'outputfile=s' => \$outfile, 'help' => \$help ); usage() if ! $ok || $help; #go! open OUT, ">>$outfile" or die "Can't open $outfile for writing: $!"; select OUT; $|=1; open(STDERR, ">&OUT"); open IN, "$infile" or die "Can't open $infile: $!"; while (<IN>) { chomp; s/\s*#.*//; push @hosts, $_ unless /^$/; } close IN; my $p = Net::Ping->new("icmp",$timeout,32); while (1) { foreach my $host (@hosts) { my @times; for (1..4) { my $t0 = [gettimeofday]; my $alive = $p->ping($host); my $t1 = tv_interval ($t0, [gettimeofday]); push @times, $alive ? # was ping successful? int($t1 * 1000) : # if so, record interval $timeout * 1000; # if not, record timeout val } my ($sec, $min, $hr, $day, $month, $year) = (localtime)[0..5]; my $timestamp = sprintf("%04d-%02d-%02d,%02d:%02d:%02d", $year + 1900, $month + 1, $day, $hr, $min, $sec); print "$timestamp,$host,", join ( ',', @times ), "\n"; } sleep $yawn; } $p->close(); sub usage { (my $msg = <<" MSG") =~ s/^\s{3}//mg; Usage: $0 [-w timeout] [-s sleep] [-i inputfile] [-o outputfile] [-h] Options: -w timeout Timeout in seconds to wait for each reply (default $timeout seconds) -s sleep Sleep time in seconds to pause after pinging through hostlist (default $yawn seconds) -i inputfile File containing list of hosts to ping (default $infile) -o outputfile Output log file (default $outfile) -h Displays this help MSG die $msg; }

The input file is just a list of hosts separated by newlines. Comments begin with #. This really seems like a nice script... er, if it worked reliably. :-)

I suspect this is being caused by some transient network condition or occurrence. (I wrote this thing because we're having trouble with our Qwest (ugh) VPNs.) However, like you, I can't force the error, and I can't figure out how it could cause the behavior I'm seeing. I'm starting to think this is <gulp> a bug in Perl or one of the modules I'm calling.

Something might be happening to $p itself. I haven't tried moving this definition inside one of the loops, but that might be next. It's such a sporadic thing, though -- I've been running it since yesterday with no error, but I saw the problem four times between Friday and Monday. Aargh!


In reply to Re: Re: Re: Re: Collecting ping times by EyeOpener
in thread Collecting ping times by EyeOpener

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.