bsimonds has asked for the wisdom of the Perl Monks concerning the following question:

I will preemptively apologize for my lack info regarding the stratus set up we have. I am using Net::SSH::Perl to connect to a stratus host, run a command, and I am trying to capture the result. The problem is, I am only capturing the first line of the result. Here is the jist of the perl code I have:
my $ssh = Net::SSH::Perl->new($host,protocol=>2, interactive=>1); $ssh->login($user, $pass, 1); my $cmd = 'some_command ' . $cmd_opt; my($stdout, $stderr, $exit) = $ssh->cmd($cmd); print "OUT:$stdout\n ERR:$stderr\n EXIT:$exit\n";
This returns:
OUT: First Line ERR: EXIT:0
But, when I ssh to the stratus module and run the command manually, I get:
bash$ cmd opt First Line Second Line bash$
I really need what is returned what is on the second line. (or subsequent lines) Some history: I am using Net::SSH::Perl because using auth keys is not an option. I dont know why, but that was what I was told, so I have to have a solution that passes the username and pw. Thanks, B

Replies are listed 'Best First'.
Re: Net::SSH::Perl and Stratus (VOS)
by tachyon-II (Chaplain) on Jun 12, 2008 at 16:50 UTC

    Probably not helpful but you are getting a second (albeit blank) line.

    FWIW you are supressing the shell in your login by passing the 3rd true param. This would seem at odds with the interactive=>1 in your new. The default for interactive is 0 - perhaps it behaves approptiately if you remove that?

    As a sanity check printing $cmd before you exec it would make sense just in case it is not what you think.

      The blank line is because the command returns one new line, and I am explicitly printing a newline in perl print command. I was pretty sure I had tried just about every combination of params just in case there was something goofy, but I double checked and tried it both with interactive 1 and not suppressing the shell, and interactive off and supressing the shell to no avail. I did find some insight on how to sort of run a trace on the Stratus command, and it appears to actually be running running multiple commands behind the scenes. I am pretty sure that is the issue. Thanks for your feedback! B

        it appears to actually be running running multiple commands behind the scenes. I am pretty sure that is the issue.

        An extremely ugly hack springs to mind

        (undef,$stderr,$exit) = $ssh->cmd("command --opts > tmp.txt"); ($stdout) = $ssh->cmd("cat tmp.txt"); or ($stdout) = $ssh->cmd("command --opts > tmp.txt && cat tmp.txt");

        Running this command with nohup might be worth trying as well. You may find Net::SSH2 works better.