Re: [Ssh-sftp-perl-users] Problem getting output using Net::SSH2
Brought to you by:
dbrobins
From: Steve P. <st...@fo...> - 2011-05-05 05:52:49
|
Hmm, the sleep got it to work. Does this mean that 'blocking' being set to 1 doesn't actually mean that the command executed by the shell blocks until it returns ? or is blocking set to 1 or 0 something else entirely ? Which I guess means that the next question is 'how do you get it to wait until output returns' for a command that could return in an indefinite amount of time ? (without the obvious of lowest common denominator and getting all commands to wait for 20 seconds or so) Also, thanks for the speedy response :-) -- Steve. On 5/05/2011 3:30 PM, Fitzpatrick, Robert M (Rob) wrote: > > First, can you confirm that it is a simple timing issue, and not > something about the input or output of your command? What if you just > run a "sleep 1", does that cause your issue? Sleep 10? > > That will also give the rest of us a replicatable test situation if we > can't resolve this quickly. > > Best of luck, > Rob > > -----Original Message----- > From: Steve Phillips [mailto:st...@fo...] > Sent: Wednesday, May 04, 2011 8:54 PM > To: ssh...@li... > Subject: [Ssh-sftp-perl-users] Problem getting output using Net::SSH2 > > 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. > |