Hello, I am seeking help with a particular problem using Net::SSH::Perl in a mason environment. I have looked at http://www.perlmonks.org/?node_id=438169 which is a similar problem but did not see a resolution there, so I figured that I should ask. When I run the script from the CLI, everything outputs and returns as expected. I am passing an argument from a form to the script and it hangs on "channel 1: close_read" Below you will find the relevant (probably could be done much better) code and the output of my httpd error log: CODE:
<%args> $pingserver </%args> <%perl> use Net::SSH::Perl; use Math::GMP; use IO::Select; #my $pingserver='172.16.50.4'; #This is for testing purposes only my $pingme ="ping -c1 $pingserver"; my $server='<ip_address>'; #cleaned for posting a question my $username='root'; my $ssh = Net::SSH::Perl->new($server, debug=>1,options =>[ "UserKnown +HostsFile /var/www/.ssh/known_hosts2" ]); $ssh->login($username) or die "Login Failed!!!\n"; my ($out, $err, $exit) = $ssh->cmd($pingme); </%perl> <center><br><% $out %></center>
Here is the output in my httpd error log:
<my_machine>: Reading configuration data /var/www/.ssh/config <my_machine>: Reading configuration data /etc/ssh_config <my_machine>: Connecting to <IP_address>, port 22. <my_machine>: Remote version string: SSH-2.0-OpenSSH_3.8.1p1 Debian-8. +sarge.4 <my_machine>: Remote protocol version 2.0, remote software version Ope +nSSH_3.8.1p1 Debian-8.sarge.4 <my_machine>: Net::SSH::Perl Version 1.30, protocol version 2.0. <my_machine>: No compat match: OpenSSH_3.8.1p1 Debian-8.sarge.4. <my_machine>: Connection established. <my_machine>: Sent key-exchange init (KEXINIT), wait response. <my_machine>: Algorithms, c->s: 3des-cbc hmac-sha1 none <my_machine>: Algorithms, s->c: 3des-cbc hmac-sha1 none <my_machine>: Entering Diffie-Hellman Group 1 key exchange. <my_machine>: Sent DH public key, waiting for reply. <my_machine>: Received host key, type 'ssh-dss'. <my_machine>: Host '<IP_Address>' is known and matches the host key.<m +y_machine>: Computing shared secret key. <my_machine>: Verifying server signature. <my_machine>: Waiting for NEWKEYS message. <my_machine>: Enabling incoming encryption/MAC/compression. <my_machine>: Send NEWKEYS, enable outgoing encryption/MAC/compression +. <my_machine>: Sending request for user-authentication service. <my_machine>: Service accepted: ssh-userauth. <my_machine>: Trying empty user-authentication request. <my_machine>: Authentication methods that can continue: publickey,keyb +oard-interactive. <my_machine>: Next method to try is publickey. <my_machine>: Trying pubkey authentication with key file '/.ssh/id_dsa +' <my_machine>: Login completed, opening dummy shell channel. <my_machine>: channel 0: new [client-session] <my_machine>: Requesting channel_open for channel 0. <my_machine>: channel 0: open confirm rwindow 0 rmax 32768 <my_machine>: Got channel open confirmation, requesting shell. <my_machine>t: Requesting service shell on channel 0. <my_machine>: channel 1: new [client-session] <my_machine>: Requesting channel_open for channel 1. <my_machine>: Entering interactive session. <my_machine>: Sending command: ping -c1 172.16.50.4 <my_machine>: Requesting service exec on channel 1. <my_machine>: channel 1: open confirm rwindow 0 rmax 32768 <my_machine>: channel 1: rcvd eof <my_machine>: channel 1: output open -> drain <my_machine>: input_channel_request: rtype exit-status reply 0 <my_machine>: channel 1: rcvd close <my_machine>: channel 1: input open -> closed <my_machine>: channel 1: close_read
Since it works fine when I use the command in the CLI, I am guessing that it is just failing to complete closing the connection. Here is the output of the command when I do it in the CLI with $pingserver defined to a given IP for testing:

<my_machine>: Reading configuration data /root/.ssh/config <my_machine>: Reading configuration data /etc/ssh_config <my_machine>: Allocated local port 1023. <my_machine>: Connecting to <IP_Address>, port 22. <my_machine>: Remote version string: SSH-2.0-OpenSSH_3.8.1p1 Debian-8. +sarge.4 <my_machine>: Remote protocol version 2.0, remote software version Ope +nSSH_3.8.1p1 Debian-8.sarge.4 <my_machine>: Net::SSH::Perl Version 1.30, protocol version 2.0. <my_machine>: No compat match: OpenSSH_3.8.1p1 Debian-8.sarge.4. <my_machine>: Connection established. <my_machine>: Sent key-exchange init (KEXINIT), wait response. <my_machine>: Algorithms, c->s: 3des-cbc hmac-sha1 none <my_machine>: Algorithms, s->c: 3des-cbc hmac-sha1 none <my_machine>: Entering Diffie-Hellman Group 1 key exchange. <my_machine>: Sent DH public key, waiting for reply. <my_machine>: Received host key, type 'ssh-dss'. <my_machine>: Host '<IP_Address>' is known and matches the host key. <my_machine>: Computing shared secret key. <my_machine>: Verifying server signature. <my_machine>: Waiting for NEWKEYS message. <my_machine>: Enabling incoming encryption/MAC/compression. <my_machine>: Send NEWKEYS, enable outgoing encryption/MAC/compression +. <my_machine>: Sending request for user-authentication service. <my_machine>: Service accepted: ssh-userauth. <my_machine>: Trying empty user-authentication request. <my_machine>: Authentication methods that can continue: publickey,keyb +oard-interactive. <my_machine>: Next method to try is publickey. <my_machine>: Trying pubkey authentication with key file '/root/.ssh/i +d_dsa' <my_machine>: Login completed, opening dummy shell channel. <my_machine>: channel 0: new [client-session] <my_machine>: Requesting channel_open for channel 0. <my_machine>: channel 0: open confirm rwindow 0 rmax 32768 <my_machine>: Got channel open confirmation, requesting shell. <my_machine>: Requesting service shell on channel 0. <my_machine>: pingme: ping -c1 172.16.50.4 <my_machine>: channel 1: new [client-session] <my_machine>: Requesting channel_open for channel 1. <my_machine>: Entering interactive session. <my_machine>: Sending command: ping -c1 172.16.50.4 <my_machine>: Requesting service exec on channel 1. <my_machine>: channel 1: open confirm rwindow 0 rmax 32768 <my_machine>: channel 1: rcvd eof <my_machine>: channel 1: output open -> drain <my_machine>: input_channel_request: rtype exit-status reply 0 <my_machine>: channel 1: rcvd close <my_machine>: channel 1: input open -> closed <my_machine>: channel 1: close_read <my_machine>: channel 1: obuf empty <my_machine>: channel 1: output drain -> closed <my_machine>: channel 1: close_write <my_machine>: channel 1: send close <my_machine>: channel 1: full closed OUT: PING 172.16.50.4 (172.16.50.4) 56(84) bytes of data. 64 bytes from 172.16.50.4: icmp_seq=1 ttl=62 time=9.23 ms --- 172.16.50.4 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 9.239/9.239/9.239/0.000 ms err: Exit: 0

I believe that there is something that is causing the script to not get to "full closed" when I call it from the mason environment, but I have no idea what it might be. Any help would be greatly appreciated.

In reply to Net::SSH::Perl hanging in mason environment. Seeking wisdon and help :) by raisputin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.