CPAN::Forum
Net-SSH2 - Issues with
| Posted on Wed Apr 4 21:08:53 2007 by samnelson |
| Issues with |
|
I was using the standard example that David Robbins includes with this awesome module to connect to some Brocade SAN switches. Some switches which I connected to would return command output fine, but occasionally the output would be "undef". Other switches would never return command output, always undef. Here is a slimmed down version of the original code:
#!/usr/bin/perl -w
use Net::SSH2;
use IO::Scalar;
my $ssh2 = Net::SSH2->new;
#$ssh2->debug(1);
die "can't connect" unless $ssh2->connect('hostname.domain.com');
die "can't authenticate" unless $ssh2->auth_password("username", "password");
sub _read {
my $handle = shift;
while (my $line = <$handle>) {
chomp $line;
print "$line\n";
}
}
# (c) type it over a channel
$chan = $ssh2->channel;
$chan->exec('command') or die;
_read($chan);
After some digging and hair pulling, I realized that something was up with the poll timeout. I bumped the timeout up from the default 250ms to 500ms and that fixed my problem. Here's the code I added (I found an example in the Net-SSH2.t file).
Changed the last few lines to:
# (c) type it over a channel
$chan = $ssh2->channel;
$chan->exec('command') or die;
## Setup polling timeout
my @poll = { handle => $chan, events => ['in'] };
$ssh2->poll(500, \@poll);
_read($chan);
Hope that helps,
Sam
|
| Write a response |
(2)
]