use strict; my $NETE_FAILURE = -1; my $NETE_SUCCESS = 0; my $timeout = 10; eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm $timeout; my $Error = &Rsh("","perl s1.pl"); print "Error::$Error\n"; if ($Error == $NETE_FAILURE) { die "Failure\n"; } alarm 0; }; if ($@) { if ($@ eq "alarm\n") { die "TimeOut\n"; } } else { print "Success\n"; } sub Rsh { my($MachineName,$Command,$ErrorText,$Length); if (scalar(@_) != 2) { print ("Error:Wrong number of arguments supplied\n"); return ($NETE_FAILURE); } ($MachineName,$Command)=@_; # Get the machine OS my $OS=$^O; if ($OS=~ m/hpux/i) { $Command = "remsh" . " $MachineName" . " $Command"; } elsif ($OS =~ /MSWin32/i) { $Command = "rsh" . " $MachineName" . " -n $Command"; } else { $Command = "rsh" . " $MachineName" . " $Command"; } #Creating temporary file my $ErrorFile = "RH".$$; my $Error = 0xffff & system("($Command 2>$ErrorFile)"); # Open the error file and see if it has some contents if( open (fhError, "< $ErrorFile")) { while () { $ErrorText .= $_; } $Length = scalar(split(//,$ErrorText)); if($Length != 0 ) { print ("Error:$ErrorText"); close (fhError); unlink ($ErrorFile); return ($NETE_FAILURE); } else { close (fhError); } } unlink ($ErrorFile); if ($Error != 0 ) { print ("Error:Executed command $Command with error return status\n"); return ($NETE_FAILURE); } return ($NETE_SUCCESS); }