ryder has asked for the wisdom of the Perl Monks concerning the following question:
Heelo Perl Monks,
I try to connect to a network appliance using Net::Openssh. Simple commands like ls /tmp or cat /etc/hosts are working.
But I try to capture the output from a proprietary command, called dbedit. The appliance have a standard Openssh server installed, version OpenSSH_4.3p2, OpenSSL 0.9.8b 04 May 2006 The server cannot be updated. here my test programm:
#!/usr/bin/perl use Net::OpenSSH; my $host = "10.100.110.51"; my $user = "admin"; my $pass = "my_pw"; #$Net::OpenSSH::debug=-1; my $ssh = Net::OpenSSH->new(host=>$host, user=>$user, password=>$pass, master_opts => [-v, -o => "StrictHostKeyCh +ecking=no"], ); $ssh->error and die "Couldn't establish SSH connection: ". $ssh->error +; my $xxx = "source /opt/CPshrd-R77/tmp/.CPprofile.sh ; /opt/CPsuite-R7 +7/fw1/bin/dbedit --h"; #my (@ls,$errput) = $ssh->capture2({tty => 1},"/opt/CPsuite-R77/fw1/ +bin/dbedit --h"); my (@ls,$errput) = $ssh->capture2({tty => 1},$xxx); $ssh->error and die "remote ls command failed: " . $ssh->error; print"LS:@ls\n"; print"ERR:$errput\n";
As you can see by the code. I already tried some hacks to solve the problem. But any additional option I integrated into the code. Did not solve the problem. Interesting ist that the Debug-Output is showing the output from the command, but it seems this output did not get back through the tunnel to the ssh client. Please finde following the debug output from a connection establishment test:
t2305@tdtest:~$ ./td_open.pl # open_ex: ['ssh','-V'] # io3 mloop, cin: 0, cout: 1, cerr: 0 # io3 fast, cin: 0, cout: 1, cerr: 0 # stdout, bytes read: 59 at offset 0 #> 4f 70 65 6e 53 53 48 5f 36 2e 36 2e 31 70 31 20 55 62 75 6e 74 75 2 +d 32 75 62 75 6e 74 75 32 2c | OpenSSH_6.6.1p1 Ubuntu-2ubuntu2, #> 20 4f 70 65 6e 53 53 4c 20 31 2e 30 2e 31 66 20 36 20 4a 61 6e 20 3 +2 30 31 34 0a | OpenSSL 1.0.1f 6 Jan 2014. # io3 fast, cin: 0, cout: 1, cerr: 0 # stdout, bytes read: 0 at offset 59 # leaving _io3() # waiting for slave, timeout: 10, remaining: 10, sleep: 1 # _waitpid(21476) => pid: 21476, rc: 0, err: Interrupted system call # OpenSSH verion is 6.6.1p1 # ctl_path: /home/t2305/.libnet-openssh-perl/admin-10.100.110.51-21475 +-908050, ctl_dir: /home/t2305/.libnet-openssh-perl/ # _is_secure_path(dir: /home/t2305/.libnet-openssh-perl, file mode: 16 +832, file uid: 1000, euid: 1000 # _is_secure_path(dir: /home/t2305, file mode: 16877, file uid: 1000, +euid: 1000 # set_error(0 - 0) # call args: ['ssh','-v','-o','ServerAliveInterval=30','-o','ControlPe +rsist=no','-2MNx','-o','NumberOfPasswordPrompts=1','-o','PreferredAut +hentications=keyboard-interactive,password','-S','/home/t2305/.libnet +-openssh-perl/admin-10.100.110.51-21475-908050','-l','admin','10.100. +110.51','--'] # master state jumping from _STATE_START to _STATE_LOGIN # file object not yet found at /home/t2305/.libnet-openssh-perl/admin- +10.100.110.51-21475-908050, state:_STATE_LOGIN # file object not yet found at /home/t2305/.libnet-openssh-perl/admin- +10.100.110.51-21475-908050, state:_STATE_LOGIN # file object not yet found at /home/t2305/.libnet-openssh-perl/admin- +10.100.110.51-21475-908050, state:_STATE_LOGIN # file object not yet found at /home/t2305/.libnet-openssh-perl/admin- +10.100.110.51-21475-908050, state:_STATE_LOGIN # file object not yet found at /home/t2305/.libnet-openssh-perl/admin- +10.100.110.51-21475-908050, state:_STATE_LOGIN # tracer attached, ssh pid: 21477, tracer pid: 21478 # file object not yet found at /home/t2305/.libnet-openssh-perl/admin- +10.100.110.51-21475-908050, state:_STATE_LOGIN OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: Applying options for * debug1: Connecting to 10.100.110.51 [10.100.110.51] port 22. debug1: Connection established. debug1: identity file /home/t2305/.ssh/id_rsa type -1 debug1: identity file /home/t2305/.ssh/id_rsa-cert type -1 debug1: identity file /home/t2305/.ssh/id_dsa type -1 debug1: identity file /home/t2305/.ssh/id_dsa-cert type -1 debug1: identity file /home/t2305/.ssh/id_ecdsa type -1 debug1: identity file /home/t2305/.ssh/id_ecdsa-cert type -1 debug1: identity file /home/t2305/.ssh/id_ed25519 type -1 debug1: identity file /home/t2305/.ssh/id_ed25519-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2 debug1: Remote protocol version 2.0, remote software version OpenSSH_4 +.3 debug1: match: OpenSSH_4.3 pat OpenSSH_4* compat 0x00000000 debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client aes128-ctr hmac-md5 none debug1: kex: client->server aes128-ctr hmac-md5 none debug1: sending SSH2_MSG_KEXDH_INIT debug1: expecting SSH2_MSG_KEXDH_REPLY debug1: Server host key: RSA 49:07:7a:17:e1:26:47:12:3a:08:70:1e:2a:6f +:b3:39 debug1: Host '10.100.110.51' is known and matches the RSA host key. debug1: Found key in /home/t2305/.ssh/known_hosts:1 debug1: ssh_rsa_verify: signature correct debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: Roaming not allowed by server debug1: SSH2_MSG_SERVICE_REQUEST sent # file object not yet found at /home/t2305/.libnet-openssh-perl/admin- +10.100.110.51-21475-908050, state:_STATE_LOGIN debug1: SSH2_MSG_SERVICE_ACCEPT received This system is for authorized use only. debug1: Authentications that can continue: publickey,password debug1: Next authentication method: password # passwd/passphrase requested (admin@10.100.110.51's password:) # file object not yet found at /home/t2305/.libnet-openssh-perl/admin- +10.100.110.51-21475-908050, state:_STATE_AWAITING_MUX # file object not yet found at /home/t2305/.libnet-openssh-perl/admin- +10.100.110.51-21475-908050, state:_STATE_AWAITING_MUX debug1: Authentication succeeded (password). Authenticated to 10.100.110.51 ([10.100.110.51]:22). debug1: setting up multiplex master socket debug1: channel 0: new [/home/t2305/.libnet-openssh-perl/admin-10.100. +110.51-21475-908050] debug1: Entering interactive session. # file object found at /home/t2305/.libnet-openssh-perl/admin-10.100.1 +10.51-21475-908050 # master state jumping from _STATE_AWAITING_MUX to _STATE_RUNNING # call args: ['ssh','-O','check','-T','-S','/home/t2305/.libnet-openss +h-perl/admin-10.100.110.51-21475-908050','-l','admin','10.100.110.51' +,'--'] # open_ex: ['ssh','-O','check','-T','-S','/home/t2305/.libnet-openssh- +perl/admin-10.100.110.51-21475-908050','-l','admin','10.100.110.51',' +--'] # io3 mloop, cin: 0, cout: 1, cerr: 0 # io3 fast, cin: 0, cout: 1, cerr: 0 debug1: multiplexing control connection debug1: channel 1: new [mux-control] # stdout, bytes read: 28 at offset 0 #> 4d 61 73 74 65 72 20 72 75 6e 6e 69 6e 67 20 28 70 69 64 3d 32 31 3 +4 37 37 29 0d 0a | Master running (pid=21477).. # io3 fast, cin: 0, cout: 1, cerr: 0 # stdout, bytes read: 0 at offset 28 # leaving _io3() debug1: channel 1: free: mux-control, nchannels 2 # _waitpid(21483) => pid: 21483, rc: 0, err: # call args: ['ssh','-qtt','-S','/home/t2305/.libnet-openssh-perl/admi +n-10.100.110.51-21475-908050','-l','admin','10.100.110.51','--','sour +ce /opt/CPshrd-R77/tmp/.CPprofile.sh && /opt/CPsuite-R77/fw1/bin/dbe +dit --h'] # open_ex: ['ssh','-qtt','-S','/home/t2305/.libnet-openssh-perl/admin- +10.100.110.51-21475-908050','-l','admin','10.100.110.51','--','source + /opt/CPshrd-R77/tmp/.CPprofile.sh && /opt/CPsuite-R77/fw1/bin/dbedi +t --h'] # io3 mloop, cin: 0, cout: 1, cerr: 1 # io3 fast, cin: 0, cout: 1, cerr: 1 debug1: multiplexing control connection debug1: channel 1: new [mux-control] debug1: channel 2: new [client-session] debug1: Sending environment. debug1: Sending env LC_PAPER = de_DE.UTF-8 debug1: Sending env LC_ADDRESS = de_DE.UTF-8 debug1: Sending env LC_MONETARY = de_DE.UTF-8 debug1: Sending env LC_NUMERIC = de_DE.UTF-8 debug1: Sending env LC_TELEPHONE = de_DE.UTF-8 debug1: Sending env LC_IDENTIFICATION = de_DE.UTF-8 debug1: Sending env LANG = en_US.UTF-8 debug1: Sending env LC_MEASUREMENT = de_DE.UTF-8 debug1: Sending env LC_TIME = de_DE.UTF-8 debug1: Sending env LC_NAME = de_DE.UTF-8 debug1: Sending command: source /opt/CPshrd-R77/tmp/.CPprofile.sh && +/opt/CPsuite-R77/fw1/bin/dbedit --h # stdout, bytes read: 883 at offset 0 #> 55 73 61 67 65 3a 20 64 62 65 +64 69 74 20 5b 2d 6c 6f 63 61 6c 5d 20 7c 20 5b 2d 73 20 73 65 72 | U +sage: dbedit [-local] | [-s ser #> 76 65 72 + 5d 20 5b 2d 63 20 63 65 72 74 69 66 69 63 61 74 65 20 66 69 6c 65 20 + 7c 20 2d 75 20 75 | ver] [-c certificate file | -u udebug1: client_i +nput_channel_req: channel 2 rtype exit-status reply 0 debug1: channel 2: free: client-session, nchannels 3 debug1: channel 1: free: mux-control, nchannels 2 #> 73 65 72 5d 20 5b 2d 70 20 70 61 73 73 77 6f 72 64 5d 20 5b 2d 66 2 +0 66 69 6c 65 6e 61 6d 65 5d | ser] [-p password] [-f filename] #> 20 5b 2d 72 20 64 62 2d 6f 70 65 6e 2d 72 65 +61 73 6f 6e 5d 20 5b 2d 68 65 6c 70 5d 20 5b 96 69 | [-r db-open-rea +son] [-help] [.i #> 67 6e 6f 72 65 5f 73 63 + 72 69 70 74 5f 66 61 69 6c 75 72 65 5d 20 5b 2d 63 6f 6e 74 69 6e 75 + 65 | gnore_script_failure] [-continue #> 5 +f 75 70 64 61 74 69 6e 67 5d 0d 0a 0d 0a 43 6f 6d 6d 61 6e 64 73 3a 0 +d 0a 0d 0a 63 72 65 61 74 | _updating]....Commands:....creat + #> 65 20 3c 6f 62 6a 65 63 74 5f 74 79 70 65 3e 20 +3c 6f 62 6a 65 63 74 5f 6e 61 6d 65 3e 0d 0a 6d | e <object_type> <ob +ject_name>..m + #> 6f 64 69 66 79 20 3c 74 61 + 62 6c 65 5f 6e 61 6d 65 3e 20 3c 6f 62 6a 65 63 74 5f 6e 61 6d 65 3e + | odify <table_name> <object_name> #> 20 3c 66 69 65 6c 64 5f 6e 61 6d 65 3e 20 3c 7 +6 61 6c 75 65 3e 0d 0a 72 65 6e 61 6d 65 20 3c 74 | <field_name> <va +lue>..rename <t #> 61 62 6c 65 5f 6e 61 6d +65 3e 20 3c 6f 62 6a 65 63 74 5f 6e 61 6d 65 3e 20 3c 6e 65 77 5f 6f +62 | able_name> <object_name> <new_ob #> 6a + 65 63 74 5f 6e 61 6d 65 3e 0d 0a 75 70 64 61 74 65 20 3c 74 61 62 6c + 65 5f 6e 61 6d 65 3e 20 | ject_name>..update <table_name> + #> 3c 6f 62 6a 65 63 74 5f 6e 61 6d 65 3e 0d 0a 75 7 +0 64 61 74 65 5f 61 6c 6c 0d 0a 64 65 6c 65 74 | <object_name>..updat +e_all..delet + #> 65 20 3c 74 61 62 6c 65 5f +6e 61 6d 65 3e 20 3c 6f 62 6a 65 63 74 5f 6e 61 6d 65 3e 0d 0a 70 72 +| e <table_name> <object_name>..pr #> 69 6e 74 20 3c 74 61 62 6c 65 5f 6e 61 6d 65 3e + 20 3c 6f 62 6a 65 63 74 5f 6e 61 6d 65 3e 0d 0a | int <table_name> < +object_name>.. #> 70 72 69 6e 74 78 6d 6c 2 +0 3c 74 61 62 6c 65 5f 6e 61 6d 65 3e 20 3c 6f 62 6a 65 63 74 5f 6e 6 +1 | printxml <table_name> <object_na #> 6d +65 3e 0d 0a 77 68 65 72 65 75 73 65 64 20 3c 74 61 62 6c 65 5f 6e 61 +6d 65 3e 20 3c 6f 62 6a | me>..whereused <table_name> <obj + #> 65 63 74 5f 6e 61 6d 65 3e 0d 0a 61 64 64 65 6c 65 + 6d 65 6e 74 20 3c 74 61 62 6c 65 5f 6e 61 6d | ect_name>..addelement + <table_nam #> 65 3e 20 3c 6f 62 6a 65 63 74 5f 6e 61 6d 65 3e 20 3c 66 69 65 6c 6 +4 5f 6e 61 6d 65 3e 20 3c 76 | e> <object_name> <field_name> <v #> 61 6c 75 65 3e 0d 0a 72 6d 65 6c 65 6d 65 6e 74 20 3c 74 61 62 6c 6 +5 5f 6e 61 6d 65 3e 20 3c 6f | alue>..rmelement <table_name> <o #> 62 6a 65 63 74 5f 6e 61 6d 65 3e 20 3c 66 69 65 6c 64 5f 6e 61 6d 6 +5 3e 20 3c 76 61 6c 75 65 3e | bject_name> <field_name> <value> #> 0d 0a 72 6d 62 79 69 6e 64 65 78 20 3c 74 61 62 6c 65 5f 6e 61 6d 6 +5 3e 20 3c 6f 62 6a 65 63 74 | ..rmbyindex <table_name> <object #> 5f 6e 61 6d 65 3e 20 3c 66 69 65 6c 64 5f 6e 61 6d 65 3e 20 3c 69 6 +e 64 65 78 5f 6e 75 6d 62 65 | _name> <field_name> <index_numbe #> 72 3e 0d 0a 61 64 64 5f 6f 77 6e 65 64 5f 72 65 6d 6f 76 65 5f 6e 6 +1 6d 65 20 3c 74 61 62 6c 65 | r>..add_owned_remove_name <table #> 5f 6e 61 6d 65 3e 20 3c 6f 62 6a 65 63 74 5f 6e 61 6d 65 3e 20 3c 6 +6 69 65 6c 64 5f 6e 61 6d 65 | _name> <object_name> <field_name #> 3e 20 3c 76 61 6c 75 65 3e 0d 0a 69 73 5f 64 65 6c 65 74 65 5f 61 6 +c 6c 6f 77 65 64 20 3c 74 61 | > <value>..is_delete_allowed <ta #> 62 6c 65 5f 6e 61 6d 65 3e 20 3c 6f 62 6a 65 63 74 5f 6e 61 6d 65 3 +e 0d 0a 73 65 74 5f 70 61 73 | ble_name> <object_name>..set_pas #> 73 20 3c 75 73 65 72 3e 20 3c 70 61 73 73 77 6f 72 64 3e 0d 0a 71 7 +5 69 74 20 5b 2d 75 70 64 61 | s <user> <password>..quit [-upda #> 74 65 5f 61 6c 6c 7c 2d 6e 6f 75 70 64 61 74 65 5d 0d 0a + | te_all|-noupdate].. # io3 fast, cin: 0, cout: 1, cerr: 1 # stdout, bytes read: 0 at offset 883 # stderr, bytes read: 0 # leaving _io3() # _waitpid(21484) => pid: 21484, rc: 22272, err: # set_error(5 - child exited with code 87) remote ls command failed: child exited with code 87 at ./td_open.pl li +ne 20. # DESTROY(Net::OpenSSH=HASH(0x854d900), pid: 21477) # sending exit control to master # call args: ['ssh','-O','exit','-T','-S','/home/t2305/.libnet-openssh +-perl/admin-10.100.110.51-21475-908050','-l','admin','10.100.110.51', +'--'] # open_ex: ['ssh','-O','exit','-T','-S','/home/t2305/.libnet-openssh-p +erl/admin-10.100.110.51-21475-908050','-l','admin','10.100.110.51','- +-'] # io3 mloop, cin: 0, cout: 1, cerr: 0 # io3 fast, cin: 0, cout: 1, cerr: 0 debug1: multiplexing control connection debug1: channel 1: new [mux-control] debug1: channel 0: free: /home/t2305/.libnet-openssh-perl/admin-10.100 +.110.51-21475-908050, nchannels 2 debug1: channel 1: free: mux-control, nchannels 1 Transferred: sent 1888, received 2672 bytes, in 0.6 seconds Bytes per second: sent 3406.9, received 4821.6 debug1: Exit status -1 # stdout, bytes read: 20 at offset 0 #> 45 78 69 74 20 72 65 71 75 65 73 74 20 73 65 6e 74 2e 0d 0a + | Exit request sent... # io3 fast, cin: 0, cout: 1, cerr: 0 # stdout, bytes read: 0 at offset 20 # leaving _io3() # _waitpid(21485) => pid: 21485, rc: 0, err: # set_error(1 - aborted) # master state jumping from _STATE_RUNNING to _STATE_KILLING # master 21477 exited, rc:65280, err: # master state jumping from _STATE_KILLING to _STATE_GONE
Is there anybody out there who can help me to capture the output from this command.
ciao ryder
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Q: Cannot get the capture from connection with Net::Openssh?
by salva (Canon) on May 05, 2015 at 08:25 UTC | |
by ryder (Initiate) on May 05, 2015 at 09:54 UTC |