in reply to Trying to get alarm to work...
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. } # ... }
|
|---|