in reply to Net::SSH2 to capture multiple commands on remote system

Well, nothing stops you from pushing the retrieved data in an array instead of passing it to print. For instance:
$chan->shell(); print $chan "$cmd1\n"; @out1 = <$chan>; print $chan "$cmd2\n"; @out2 = <$chan>; ...

Unfortunately, Net::SSH2 is full of quirks and using it in the way you are doing is unreliable. You can see it if you run some slow commands, for instance, try $cmd1 = sleep 2.

If you are on a Linux/Unix system, your better option would be to switch to Net::OpenSSH.

Otherwise, you can use Net::SSH::Any which is able to run over Net::SSH2 and provides a friendlier interface while taking care of the ugly details for you... well, mostly, because there are several bugs on the current stable version of libssh2 that can not be worked around.

Replies are listed 'Best First'.
Re^2: Net::SSH2 to capture multiple commands on remote system
by bellis (Initiate) on Sep 17, 2014 at 04:47 UTC
    Salva, That was exactly what I was looking for. Works perfectly. Thank you so much! I have gone down the OpenSSH path and ran into a problem I believe is an incompatibility with the version on OpenSSH on the Unix server and the type of node I am communicating with. I also looked into your SSH::Any but was not getting any returns from my commands.
      That was exactly what I was looking for. Works perfectly

      No, it doesn't. That will fail to work correctly quite often.