LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Undef handle weirdness in Net::SSH::Perl (https://www.linuxquestions.org/questions/programming-9/undef-handle-weirdness-in-net-ssh-perl-463022/)

PenguinPwrdBox 07-11-2006 01:11 PM

Undef handle weirdness in Net::SSH::Perl
 
Hey all. I have a bit of an odd problem. I am unable to connect using Net::SSH::Perl. It would seem that as soon as the new() sub is called, the handle to which the communication is assigned becomes undef. Here is the code:
Code:

#!/usr/bin/perl -w

use Net::SSH::Perl;

$ssh = Net::SSH::Perl->new('hostname');
$ssh->login('root','rootpass') || die;
($out, $err, $ext) = $ssh->cmd('date');
print "$out\n";

I was originally thinking that the entire SSH call was failing, however, by passing "debug=>1" to new(), it will echo progress to the command line:

Code:

sourcehostname: Reading configuration data /root/.ssh/config
sourcehostname: Reading configuration data /etc/ssh_config
sourcehostname: Allocated local port 1023.
sourcehostname: Connecting to hostname, port 22.
sourcehostname: Remote protocol version 2.0, remote software version OpenSSH_3.8.1p1
sourcehostname: Net::SSH::Perl Version 1.28, protocol version 2.0.
sourcehostname: No compat match: OpenSSH_3.8.1p1.
sourcehostname: Connection established.
Can't call method "login" on an undefined value at ./sshtest.pl line 19.

I attempted to print the $ssh var right after the new() call, and got the undef var error. What is going on here?

Also worth mentioning, is that usually the login() sub is called directly after new(). This is omitted here, as there is a key exchange. It should be noted, however, that an attempt to skip the use of login() results in the same "undefined value" error, only with the cmd sub instead of login.

TIA!

-ppb


All times are GMT -5. The time now is 03:03 AM.