Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PERL Net::Rsh error on controlling TIMEOUT

Status
Not open for further replies.

slimelord

Programmer
Dec 12, 2008
1
0
0
US
Hi there senior and experimented SEO..

I have in trouble with a big shit, on Perl, using the module rsh to connect to a list of remote sites, i have running this code:

[...]
#!/usr/bin/perl

use Net::ping;
use Net::Ifconfig::Wrapper;
use Net::Rsh;

... ...

PropagateStatus(@NodeList,$ProxyNo);
sub PropagateStatus {

local *listnodes=@_[0];

# Set remote status files to itself as the MasterProgram
local $command = "echo " .$_[1] ." > " .$status_file;
local $rsh_connection=Net::Rsh->new();
foreach (@listnodes) {
chomp($_);
print "RSH access to " ."-$username\@$_- \n";
print "Executing: $command at remote host\n";
@tmp=$rsh_connection->rsh($_,$username,$username,$command);
}
}


ok, this code, makes a rsh connection to a list of available nodes (from a file)
but suddenlly, if one node have crashed the service it still get connected,
and doesnt release from this node to connect to the next... because the module Net::Rsh doesnt have a time out to to that, so i think i have found the solution:

....

local $rsh_connection=Net::Rsh->new();
foreach (@listnodes) {
$SIG{ALRM} = \&temporizador;
$time=15;
eval {
alarm($time);


chomp($_);
print "RSH access to " ."-$username\@$_- \n";
print "Executing: $command at remote host\n";
@tmp=$rsh_connection->rsh($_,$username,$username,$command);
}
}

alarm(0);
};
if ($@ =~ /End of timer/){
print "Returns timer code\n";
}else{
print "Returns no code: $res\n";
}

sub temporizador {
# how its added
die "Timeup of timer";
}




Could someone with high level of Perl please help me add this timer function on this code? Its very usefull for scripts that makes high availability of checking process running on others machines...



*As reward I can share my script with you if you want to use it in private*

Thanks in advance Programming Gurus!
 
Move your alarm(0) to just after the eval {}'s.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top