Net::SSH::Perl sending output to STDOUT

R

ryanmhuc

I'm using Net::SSH::perl to connect to remote server but when every I
run commands it is sending output to STDOUT.

$ssh = Net::SSH::perl->new($ip);
$ssh->login($user, $pass);
($out, $err, $ext) = $ssh->cmd("ls -l");

So when I run the command instead of the the command output being put
into $out it goes straight to STDOUT. Furthermore if the password is
incorrect the $ssh->cmd stops my program. Anyone know how to get
around this?
 
R

ryanmhuc

The code is in the first post.
When it is run it the output are being sent to STDOUT while it should
be returning it to the $out variable according to Net::SSH::perl docs.
 
M

Martin Kissner

I'm using Net::SSH::perl to connect to remote server but when every I
run commands it is sending output to STDOUT.

$ssh = Net::SSH::perl->new($ip);
$ssh->login($user, $pass);
($out, $err, $ext) = $ssh->cmd("ls -l");

So when I run the command instead of the the command output being put
into $out it goes straight to STDOUT. Furthermore if the password is
incorrect the $ssh->cmd stops my program. Anyone know how to get
around this?

I used this module, too.
I only get an output after 'print $out'

There is a good example script at

http://search.cpan.org/src/DROLSKY/Net-SSH-Perl-1.25/eg/cmd.pl

to start from.

Don't forget to say
debug => 0
if you don't want to see the debug messages.

HTH
Martin
 
R

ryanmhuc

Thanks for the script but it does the same thing. If the password is
incorrect for the login i get:
"Permission denied at test.pl line 43"
and then it stops the program. The issue is I need to catch this. The
script I'm trying to create logins into about 16 different servers.
These servers passwords are not supposed to change but every once in a
while one does. I want the program to not die when it can't login to
the server but instead trap it, let me know and then continue with the
script. ANYBODY?
 
M

Martin Kissner

Thanks for the script but it does the same thing.

What same thing?
If the password is
incorrect for the login i get:
"Permission denied at test.pl line 43"
and then it stops the program.

What do you expect? If the pw is incorrect you should't be able to log
in, should you?
The issue is I need to catch this. The
script I'm trying to create logins into about 16 different servers.
These servers passwords are not supposed to change but every once in a
while one does. I want the program to not die when it can't login to
the server but instead trap it, let me know and then continue with the
script.

Then you should probably check for success.
if (your command) {
do stuff;
}
else {
do other stuff;
}

btw:
You'd probably increase your chances of getting qualified help by
avoiding TOFU quoting an providing some code example.

HTH
Martin

[ TOFU snipped ]
 
R

ryanmhuc

Martin,
I think theres a misunderstanding here. The code i am using is in the
first post. And its not like the method $ssh->login is kicking back an
error here if the pass is wrong it is exiting my program and printing
"Permission denied" to the STDOUT. Of course its not going to login if
the pass is wrong but why in the world is it halting my program?

after executing:
$ssh->login($user || $this_user, $pass);

the program dies and prints
"Permission denied at test.pl line 43"

I don't want my program to exit at this statment if the password is
incorrect. How do I do that? How do I trap it? Perhaps this is the
behavior of the module but what good is it if you can't error trap if
the password is incorrect.

Martin said:
Thanks for the script but it does the same thing.

What same thing?
If the password is
incorrect for the login i get:
"Permission denied at test.pl line 43"
and then it stops the program.

What do you expect? If the pw is incorrect you should't be able to log
in, should you?
The issue is I need to catch this. The
script I'm trying to create logins into about 16 different servers.
These servers passwords are not supposed to change but every once in a
while one does. I want the program to not die when it can't login to
the server but instead trap it, let me know and then continue with the
script.

Then you should probably check for success.
if (your command) {
do stuff;
}
else {
do other stuff;
}

btw:
You'd probably increase your chances of getting qualified help by
avoiding TOFU quoting an providing some code example.

HTH
Martin

[ TOFU snipped ]
 
M

Martin Kissner

(e-mail address removed) wrote :

please do yourself a favor and read
http://learn.to/quote
I am used to read textes from top left to bottom right and I am not
going to change this.
Martin,
I think theres a misunderstanding here. The code i am using is in the
first post.

I use a newsreader which does not show me posts which I have already
read. This is one reason why correct quoting is indispensably.
after executing:
$ssh->login($user || $this_user, $pass);

the program dies and prints
"Permission denied at test.pl line 43"

I don't want my program to exit at this statment if the password is
incorrect. How do I do that? How do I trap it?

Did you at least try my suggestion?

if ($ssh->login($user || $this_user, $pass)) {
...
}
else
...
}
It might work or not.
I will not try it, cause I don't need it right now.
and again [ TOFU snipped ]

Best regards
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top