[Ssh-sftp-perl-users] Problem getting output using Net::SSH2
Brought to you by:
dbrobins
|
From: Steve P. <st...@fo...> - 2011-05-05 03:21:21
|
Hey There,
I'm busy pulling my hair out over this one. I have a small script
similar to the below.
my $ssh2 = Net::SSH2->new();
$ssh2->debug(1);
$ssh2->connect($server) or die "Unable to connect Host $@ \n";
$ssh2->auth_publickey($userName,$publicKey,$privateKey);
my $chan = $ssh2->channel();
$chan->blocking(0);
$chan->shell();
This seems to work quite happily and a connection is established,
however - when running small commands (ls -l, whoami etc) everything
works as expected
print $chan "ls -la\n";
while (<$chan>) { print "LINE: " . $_ }
But, when I run a command that takes a while to return, I simply get a
blank output.
print $chan "vip/listmse /WideSpan/config/vipclient.conf 1 -c 'RADIUS
Server'\n";
while (<$chan>) { print "LINE: " . $_ }
The only thing I can think of is that the second command seems to take a
few miliseconds longer to produce output.
I've tried to play around with "$ssh2->poll(0)" which I read somewhere
sets polling to infinite, but still no results.
When debug is enabled I get thousands of lines similar to
Net::SSH2::Channel::read(size = 1, ext = 0)
- read 1 bytes
- read 1 total
Net::SSH2::poll: timeout = 250, array[1]
- [0] = channel
- [0] events 1
- libssh2_poll returned 1
- [0] revents 1
scrolling up the screen, which I would assume means that I have exceeded
a timeout of 250ms ?
I've tried setting blocking to 0 and 1 with no joy either. (I've found
that setting blocking to 0 when performing shell commands can lead to
interesting output tho, so I assume that interactive shell commands
should leave blocking to 1 ? setting to 0 seems to have interesting
results when trying to run commands like ls -la)
If I manually ssh into the remote box and run the command it returns
values as expected, and if I do something similar using Net::SSH::Perl
it works as well, however, Net::SSH::Perl seems to take upward of 30
seconds to create a connection which isn't an option in this environment
(and yeah - I've tried all the math module stuff which didn't seem to
make a difference :-( )
Any pointers as to why small/fast commands would work but commands that
take around 1/2 a second to run would drop out would be appreciated.
--
Steve.
|