Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Net::SSH::Any does not return output for few specific commands

by magic_007 (Initiate)
on Apr 02, 2013 at 16:24 UTC ( #1026732=perlquestion: print w/ replies, xml ) Need Help??
magic_007 has asked for the wisdom of the Perl Monks concerning the following question:

A newbie to Perl. I was trying to use Net::SSH::Any module to execute some commands on Linux box from my perl code and get the output. It works fine but for few commands.

use Net::SSH::Any; $ssh = Net::SSH::Any->new($hostname, user => $username, password => $p +assword); $out = $ssh->capture(“who am I”); print $out;

Result: No output @ all. “Who am I” command doesn’t return anything. Please let me know if I'm missing something here"

Comment on Net::SSH::Any does not return output for few specific commands
Download Code
Re: Net::SSH::Any does not return output for few specific commands
by salva (Monsignor) on Apr 02, 2013 at 16:28 UTC
    Add error checks:
    $ssh = Net::SSH::Any->new($hostname, user => $username, password => $p +assword); $ssh->error and die "unable to connect to remote host: " . $ssh->error +; $out = $ssh->capture(“who am I”); $ssh->error and die "remote command failed: " . $ssh->error; print $out;

      Thanks Salva for quick reply. I added error check but no break. The code is connecting to the host it did not die and the $ssh->error is printing 0.

        My problem got solved. Instead of "who am i" I used "whoami" and i got the output.

        I even tried "who -am -u" but it did not work but i could not find out why capture doesn't return output for those commands.

        Thanks anyways.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1026732]
Approved by herveus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2014-10-22 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (114 votes), past polls