However, running Net::SSH2-0.28, built against the latest libssh2-1.2.2, the buffer is *empty* in the first iteration - but filled correctly in subsequent iterations of the loop.use Net::SSH2; use warnings; use strict; my $buflen = 10000; my $buf1 = '0' x $buflen; my $ssh2 = Net::SSH2->new(); $ssh2->connect('xxx.xxx.xxx.xxx') or die; $ssh2->auth_password('xxx','xxxxxxx') or die "Unable to login $! \n"; my $chan = $ssh2->channel(); $chan->blocking(0); $chan->shell(); for(1 .. 2) { if($_ == 1) {$chan->write("echo \$PATH\n")} else {$chan->write("echo \$HOME\n")} select(undef,undef,undef,0.25); $chan->read($buf1, $buflen); print "BUF1: ", $buf1, "\n"; } $chan->close;
but with the latest, I'm getting:BUF1: /usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/games:/home/rob +/bin BUF1: /home/rob
I can hack my way around the problem with the latest Net::SSH2 by changing the loop to:BUF1: BUF1: /home/rob
That then produces (running the latest Net::SSH2):for($i = 0, $i < 2, $i++) { if($_ == 1) {$chan->write("echo \$PATH\n")} else {$chan->write("echo \$HOME\n")} select(undef,undef,undef,0.25); $chan->read($buf1, $buflen); if($buf1) {print "BUF1: ", $buf1, "\n"} else { print "Empty buffer ... trying again\n"; --$i; } }
Hope there's something there that helps. (I don't have time to "tune" this script at the moment - or to look at the issue with the latest version.)Empty buffer ... trying again BUF1: /usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/games:/home/rob +/bin BUF1: /home/rob
In reply to Re: Net::SSH2 to execute for loop
by syphilis
in thread Net::SSH2 to execute for loop
by godsown
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |