Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

why timeout not working in Net::OpenSSH

by aqwsh2006 (Initiate)
on Aug 07, 2013 at 06:03 UTC ( #1048257=perlquestion: print w/replies, xml ) Need Help??
aqwsh2006 has asked for the wisdom of the Perl Monks concerning the following question:

I set timeout=1 in $ssh->capture2,but this don't return after 1 seconds, and this error message is "ssh slave failed: timed out"

#!/usr/bin/perl use strict; use Net::OpenSSH; my $host=''; my $user='oracle'; my %param=( user => $user, password=>'xxxxxx', timeout => 10, port => '22' ); my $ssh = Net::OpenSSH->new($host,%param); my ($stdout,$stderr) = $ssh->capture2({timeout => 1},"echo hello; slee +p 10; echo bye"); if($stderr){ print $stderr; } $ssh->error and warn "operation didn't complete successfully: ". $ssh->error;

Replies are listed 'Best First'.
Re: why timeout not working in Net::OpenSSH
by Loops (Curate) on Aug 07, 2013 at 06:32 UTC
    Hi there,

    The problem is that Ssh doesn't have a lot of options when it comes to responding to a timeout. Checkout the Timeouts section of the documentation to see there are really two options.

    The first and default option is to close down the socket the remote system is using for input. In the ideal case the remote is configured to recognize this situation and terminate all running processes associated with the login. Clearly that's not happening on your remote, at least not while it's executing "sleep 10".

    The other option which you can enable, will terminate all connections to the remote and immediately continue the execution of your local script. The downside with this is that the remote script may continue executing, and you wont capture any of its output. To enable this option change your params to:

    my %param=( user => $user, password=>'xxxxxx', port => '22', kill_ssh_on_timeout => 1);
    You should see this error printed by your script:
    operation didn't complete successfully: ssh slave failed: timed out at + ...

      I see. Thanks

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1048257]
Approved by Corion
[Corion]: usemodperl: I'm sure you could even code that on the command line.
[usemodperl]: definitely

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2018-06-24 17:08 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.