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
HostGator.com LLC
http://support.hostgator.com