Hi fiddler42,

Coincidentally, I had to use alarm just the other day, and I was also using uptime to test it.

Have you looked at the alarm docs?  It gives a good example where, in conjunction with eval, you can branch on failure or success (ie. alarm did or didn't take place).

Something like this, perhaps (using the code example from alarm with your code):

use strict; use warnings; my @MasterMachineIndex = qw( # For example ... remote_host_1 remote_host_2 remote_host_3 ); foreach $Host (@MasterMachineIndex) { &ping; # my subroutine to ping system...works fine $Cmd = "rsh $Host uptime"; my $result = ""; eval { local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required alarm $timeout; $result = `$Cmd`; alarm 0; }; if ($@) { ($@ eq "alarm\n") or die "Unexpected error\n"; # Handle timeout here. } else { # Success here. } # ... }

s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

In reply to Re: Trying to get alarm to work... by liverpole
in thread Trying to get alarm to work... by fiddler42

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.