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;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|