Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Net-SSH2 CPAN distribution.

Report information
The Basics
Id:
80155
Status:
rejected
Priority:
Low/Low
Queue:

People
Owner:
Nobody in particular
Requestors:
jlavoy [...] hostgator.com
Cc:
AdminCc:

BugTracker
Severity:
(no value)
Broken in:
(no value)
Fixed in:
(no value)



Subject: Output capture on Long running processes.
Date: Fri, 12 Oct 2012 14:40:42 -0500
To: bug-Net-SSH2@rt.cpan.org
From: James Lavoy <jlavoy@hostgator.com>
CentOS
perl 5.8.8
Net::SSH2 0.45

Can't seem to get Net::SSH2 to do any kind of output capture on commands that take more than a quick second to run. I'm using the shell() implementation. The command does execute without any issue, but without output capture I can't really use this. Unfortunately this seems to be the best suited module for what I'm trying to do besides this problem.

The command that's being pushed is only a few lines, but the second line is a GET <script> | bash which does take 10-15 seconds to complete.

For explanations sake, lets say the commands being pushed are:
hostname
GET domain.tld/script.sh |bash
hostname -i

When pushing this, I will get the output from hostname, and nothing else.

In fact, the script returns too quickly. It almost feels like it runs, and backs out right away, without waiting for command completion.

Here is the snip of the SSH code:

                my $ssh = Net::SSH2->new();
                unless ( $ssh->connect($server) ) {
                        lock(@errors);
                        push(@errors, $server);
                        return;
                }
                unless ( $ssh->auth_publickey('root', "$key.pub", $key) ) {
                        lock(@errors);
                        push(@errors, $server);
                        return;
                }
                my $channel = $ssh->channel();
                $channel->blocking(0);
                $channel->shell();
                foreach my $cmd (@fullcmd) {
                        print $channel "$cmd\n";
                        print $_ while <$channel>;
                }
                $channel->close();

I've been through several old forums that have similar issues, but none provide any answers that have worked. I'm growing a bit frustrated.

Is this a bug? Is there a work around? Or is this just "how it is"?

Thank you for your time and attention. If you need any further information please feel free to ask.


=================================
James Lavoy
Systems Architect




Subject: Re: [rt.cpan.org #80155] AutoReply: Output capture on Long running processes.
Date: Fri, 12 Oct 2012 18:30:02 -0500
To: bug-Net-SSH2@rt.cpan.org
From: James Lavoy <jlavoy@hostgator.com>
I figured out a work around:

                my $channel = $ssh->channel();
                $channel->blocking(1);
                $channel->shell();
                my $output;
                foreach my $cmd (@fullcmd) {
                        print $channel "$cmd\n";
                }
                while ( $output !~ /^33jdG7RtabFZ4P83YbasBUmbfxsE34wW$/ ) {
                        print $output;
                        $output = <$channel>;
                }
                $channel->close();


=================================
James Lavoy
Systems Architect




On Oct 12, 2012, at 2:40 PM, Bugs in Net-SSH2 via RT <bug-Net-SSH2@rt.cpan.org> wrote:

Show quoted text

Greetings,

This message has been automatically generated in response to the
creation of a trouble ticket regarding:
"Output capture on Long running processes.",
a summary of which appears below.

There is no need to reply to this message right now.  Your ticket has been
assigned an ID of [rt.cpan.org #80155].  Your ticket is accessible
on the web at:

   https://rt.cpan.org/Ticket/Display.html?id=80155

Please include the string:

        [rt.cpan.org #80155]

in the subject line of all future correspondence about this issue. To do so,
you may reply to this message.

                       Thank you,
                       bug-Net-SSH2@rt.cpan.org

-------------------------------------------------------------------------
CentOS
perl 5.8.8
Net::SSH2 0.45

Can't seem to get Net::SSH2 to do any kind of output capture on commands that take more than a quick second to run. I'm using the shell() implementation. The command does execute without any issue, but without output capture I can't really use this. Unfortunately this seems to be the best suited module for what I'm trying to do besides this problem.

The command that's being pushed is only a few lines, but the second line is a GET <script> | bash which does take 10-15 seconds to complete.

For explanations sake, lets say the commands being pushed are:
hostname
GET domain.tld/script.sh |bash
hostname -i

When pushing this, I will get the output from hostname, and nothing else.

In fact, the script returns too quickly. It almost feels like it runs, and backs out right away, without waiting for command completion.

Here is the snip of the SSH code:

               my $ssh = Net::SSH2->new();
               unless ( $ssh->connect($server) ) {
                       lock(@errors);
                       push(@errors, $server);
                       return;
               }
               unless ( $ssh->auth_publickey('root', "$key.pub", $key) ) {
                       lock(@errors);
                       push(@errors, $server);
                       return;
               }
               my $channel = $ssh->channel();
               $channel->blocking(0);
               $channel->shell();
               foreach my $cmd (@fullcmd) {
                       print $channel "$cmd\n";
                       print $_ while <$channel>;
               }
               $channel->close();

I've been through several old forums that have similar issues, but none provide any answers that have worked. I'm growing a bit frustrated.

Is this a bug? Is there a work around? Or is this just "how it is"?

Thank you for your time and attention. If you need any further information please feel free to ask.


=================================
James Lavoy
Systems Architect
HostGator.com LLC
http://support.hostgator.com






You were setting the object in non-blocking mode and got the expecting behavior.


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.