I'm trying to read the output of a command issued using Net::SSH2. For some reason if I do not set the buffer size in the $chan2->read to close to the length of result the command does not finish. The output length is varies from about 20 bytes to over 2048. If I turn on debug ($ssh2->debug(1);) I see bytes being read but no completion. I've tried the two blocking's (ssh and channel) to no avail. I have similar issues with the write and exec options. Is there a better way to do this ? Keep in mind that I'm not the most powerful Perl programmer. And no I can't use expect. Sample code:
#!/opt/csw/bin/perl
use strict;
use warnings;
use Net::SSH2;
use constant BUFLEN => 10_0000;
my $host = "<name or IP>";
my $user = "<ID>";
my $pass = "<password>";
my $buf;
my $ssh2 = Net::SSH2->new();
my $ok = 1;
print "==> $host\n";
$ssh2->connect($host) or $ok = 0;
if ( !$ok ) {
print "Probable telnet\n";
exit(1);
}
if ( !$ssh2->auth_password( $user, $pass ) ) {
print "==> 4 pass fail\n";
exit(1);
}
my $chan2 = $ssh2->channel();
$chan2->shell();
print $chan2 ("term len 0\n");
$chan2->read( $buf, BUFLEN );
print $buf;
print $chan2 ("dir\n");
$chan2->read( $buf, BUFLEN );
print $buf;