Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
While getting perl to hop around our network and do a "uname -a"
on each machine, I run into the problem that either a machine O/S
is being re-installed, in which case the machine will return from a
ping request (how I determine which machines to rsh on to) but when
I rsh on to it, it slows the script down massively, since I have
to wait until rsh exits, (ages) and worse still, some machines refuse
a connection, and it bombs out the perl script completely.
I'm wondering if anyone has come across this kind of thing before,
or has written a script to report on O/S type (UNIX only) od machines on
a network? I'd say it would be easy if rsh had a timeout switch, but
it doesn't :-(
Thanks,
David FitzGerald.
One option is to use alarm. Put the network command in an eval block.:
eval {
local $SIG{ALRM} = sub { die "timed out\n" };
alarm(10); # ask for an alarm signal to be sent in ten second
+s
system("rsh", "blah blah"); # your code here
alarm(0); # if we're here, cancel the alarm signal
};
if ($@) { # there was an error in the eval block
die unless $@ eq "timed out\n";
# move on to the next client
} else {
# record the success
}