Link to home
Start Free TrialLog in
Avatar of chainfear
chainfear

asked on

Perl net ssh

Hi,

I got this error:
Use of uninitialized value in string at ./test.pl line 11.

after running below script:

#!/usr/bin/perl -w
 use Net::SSH::Perl;
    my $host="x.x.x.x";
    my $pass="pass";
    my $user="user";
    my $ssh = Net::SSH::Perl->new($host);
    $ssh->login($user, $pass);
    my($stdout, $stderr, $exit) = $ssh->cmd("sh run");
    print "$stdout";

Im quite new with perl. Any help?

Thanks.
Avatar of Nem Schlecht
Nem Schlecht
Flag of United States of America image

Very odd... since your script does not have 11 lines.  Is there anything you cut out of your script before posting it?

I haven't used Net::SSH::Perl, but looking at the manual page for it, all of your syntax looks correct.  Any other info that you can provide us experts?
Avatar of chainfear
chainfear

ASKER

Sorry. Below is the exact script:


#!/usr/bin/perl -w
 use Net::SSH::Perl;
    my $host="x.x.x.x";
    my $pass="pass";
    my $user="user";
    my $ssh = Net::SSH::Perl->new($host);
    $ssh->login($user, $pass);
    my($stdout, $stderr, $exit) = $ssh->cmd("sh run");
    print "$stdout";

And below is the error:
Use of uninitialized value in string at ./test.pl line 9.
Well, that's just a warning line, not an error (you have '-w' added to the shabang line).  However, it appears that you're also not getting any results.  Change line 8 to:

my($stdout, $stderr, $exit) = $ssh->cmd("echo hello");

And see if you get 'hello' as output.
Hi,

I've removed  the -w but still cannot get any output.

I've changed line 8 to be read:
 my ($stdout, $stderr, $exit) = $ssh->cmd("show version");

I am supposed to get the switch version and its running fine when I executed "show version" straight on the switch.

I missed anything?

Thank you.
Anything from the other variables?

print "OUT: $stdout\n";
print "ERR: $stderr\n";
print "Exit code: $exit\n';

Just an FYI... when I usually do something like this, I usually use "expect" instead of Perl, seems to more consistently do a better job.
Its blank...

[root@svr perl]# ./test.pl
OUT:
ERR:
Exit code:
[root@svr perl]#

I will install Net::SSH::Expect and try. BTW, I am just curious. Why it is blanked...?

Thanks for your time & effort
Not sure... should get *something* back (if nothing else, an exit code).  Net::SSH::Perl hasn't been updated in 3 years, but then again, I haven't update one of my CPAN modules in over 10 years.  SSH hasn't changed that much, so I would think this module would still work just fine.

Let me know how Net::SSH::Expect works for you.
ASKER CERTIFIED SOLUTION
Avatar of chainfear
chainfear

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Use Net::OpenSSH instead of Net::SSH::Perl