Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Net::SSH::Perl hangs while running remote command

by atcroft (Abbot)
on Mar 04, 2011 at 05:47 UTC ( #891366=note: print w/replies, xml ) Need Help??

in reply to Net::SSH::Perl hangs while running remote command

My first question would be what happens if you try to connect to the same host with a command-line SSH client?

I've recently started using Net::SSH::Perl myself (so I'm no expert), but you might try setting one or more of the following options when creating the object:

options => [ q{BatchMode yes}, q{ConnectTimeout } . $connect_timeout_in_sec, q{TCPKeepAlive yes}, ],

Also, you might try wrapping your $ssh->cmd() call in an eval() and checking to see if it completes successfully or not (perhaps similar to the following):

eval { ( $stdout, $stderr, $exit ) = $ssh->cmd($cmd); }; if ($@) { # Do something as a result }

Hope that helps. (And if you find an answer that helps, I'd love to see it as an update or reply.)

Replies are listed 'Best First'.
Re^2: Net::SSH::Perl hangs while running remote command
by sugarboy (Beadle) on Mar 07, 2011 at 00:16 UTC
    I tried by providing timeout option while creating ssh object, but which is not much of help...SSH is not timing out the command, its just waiting for the command to respond. Moreover am running the command in eval block.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://891366]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2018-04-22 07:45 GMT
Find Nodes?
    Voting Booth?