SuperSu has asked for the wisdom of the Perl Monks concerning the following question:
I'm working with WindwosXP + ActivePerl.
Code:
#!/usr/bin/perl use Net::SSH::W32Perl; my $host = 'x.x.x.x'; my $ssh = new Net::SSH::W32Perl($host); $ssh->login('XXX', XXX); my ($out, $err, $exit) = $ssh->cmd('show vlan brief'); print $out; print $err; print $exit;
Condition 1:
Make sure the ip, username, password is correct. Result:
Use of uninitialized value $out in print at ...
Use of uninitialized value $err in print at ...
Use of uninitialized value $exit in print at ...
Condition 2:
Input the ip that dose not exsit. Result:
Can't connect to 10.17.14.184: Unknown error
Condition 3:
Make sure the ip is ok but the username is wrong. Result:
Permission denied at ...
My guess is: the conenct and login part is ok but I just could not figure out why I can not get the result from the cmd function
Any help would be great, thanks in advance.
I tried the debug mode and here is the new code and output
#!/usr/bin/perl use Net::SSH::W32Perl; $ENV{HOME} = "C:\\"; my $host = '10.167.14.126'; my $ssh = new Net::SSH::W32Perl($host,debug=>1); $ssh->login('xxx', 'xxx'); my $out = $ssh->cmd('ll'); print $out;
Debug output:
Mike: Reading configuration data C:\/.ssh/config Mike: Reading configuration data /etc/ssh_config Mike: Connecting to 10.167.14.126, port 22. Mike: Socket created, turning on blocking... Mike: Remote protocol version 2.0, remote software version OpenSSH_4.3 Mike: Net::SSH::Perl Version 1.34, protocol version 2.0. Mike: No compat match: OpenSSH_4.3. Mike: Connection established. Mike: Sent key-exchange init (KEXINIT), wait response. Mike: Algorithms, c->s: 3des-cbc hmac-sha1 none Mike: Algorithms, s->c: 3des-cbc hmac-sha1 none Mike: Entering Diffie-Hellman Group 1 key exchange. Mike: Sent DH public key, waiting for reply. Mike: Received host key, type 'ssh-dss'. Mike: Host '10.167.14.126' is known and matches the host key. Mike: Computing shared secret key. Mike: Verifying server signature. Mike: Waiting for NEWKEYS message. Mike: Send NEWKEYS. Mike: Enabling encryption/MAC/compression. Mike: Sending request for user-authentication service. Mike: Service accepted: ssh-userauth. Mike: Trying empty user-authentication request. Mike: Authentication methods that can continue: publickey,gssapi-with- +mic,password. Mike: Next method to try is publickey. Mike: Next method to try is password. Mike: Trying password authentication. Mike: Login completed, opening dummy shell channel. Mike: channel 0: new [client-session] Mike: Requesting channel_open for channel 0. Mike: channel 0: open confirm rwindow 0 rmax 32768 Mike: Got channel open confirmation, requesting shell. Mike: Requesting service shell on channel 0. Mike: channel 1: new [client-session] Mike: Requesting channel_open for channel 1. sxcMike: Entering interactive session. Mike: Sending command: ll Mike: Sending command: ll (<==== why twice?) Mike: Requesting service exec on channel 1. Mike: channel 1: open confirm rwindow 0 rmax 32768 (<==== hangs her +e, no return)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::SSH::W32Perl cmd no return ???
by salva (Canon) on Jul 16, 2010 at 07:03 UTC |