Re: Net::SSH::Perl doesn't like long commands
by salva (Canon) on Jun 10, 2013 at 12:14 UTC
|
This looks like a bug on Net::SSH::Perl.
I can reproduce the problem myself. In my environment, Net::SSH::Perl hangs at some point between 8000 and 10000 characters.
Net::OpenSSH can handle the same commands without any issue (that's why I think the problem lies on Net::SSH::Perl):
#!/usr/bin/perl
use strict;
use Net::OpenSSH;
use Net::SSH::Perl;
my $host = $ARGV[0] // "localhost";
for my $len (10, 100, 1000, 2000, 4000, 6000, 8000, 10000, 20000, 5000
+0) {
my $cmd = "echo ";
$cmd .= "." x $len;
warn "trying with Net::OpenSSH, len=$len...\n";
my $ssh1 = Net::OpenSSH->new($host);
my ($stdout1, $stderr1) = $ssh1->capture($cmd) or die "Failed!\n";
warn "Failed $?!\n" if $?;
warn "trying with Net::SSH::Perl, len=$len...\n";
my $ssh2 = Net::SSH::Perl->new( $host,
# debug => 1,
options => [ "BatchMode yes",
"PasswordAuthenticati
+on no",
"ConnectTimeout 15" ]
+ );
$ssh2->login("root") or die "Failed to login: $!\n";
warn "logged\n";
my ($stdout2, $stderr2, $exit) = $ssh2->cmd($cmd);
warn "Failed $exit!\n" if $exit;
}
| [reply] [Watch: Dir/Any] [d/l] |
|
hangs at some point between 8000 and 10000 characters.
What's the betting that it is somewhere around 8192, the size of PerlIO IO buffers since 5.1(2|4|?).
Maybe someone how has reproduced it could try disabling the buffering and see if that changes anything.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [Watch: Dir/Any] |
|
I see syswrite calls in this code
http://cpansearch.perl.org/src/SCHWIGON/Net-SSH-Perl-1.35/lib/Net/SSH/Perl/Packet.pm
Looks like it's not protected from EAGAIN and from case when syswrite didn't write all data.
sysread calls are protected.
| [reply] [Watch: Dir/Any] |
|
It is very unlikely that buffering may be the root of the problem because of the way the SSH protocol is internally structured in several layers. A buffering issue would have manifested itself as a wider set of problems.
| [reply] [Watch: Dir/Any] |
|
Setting $|++ doesn't help unfortunately (and the value on my boxes are different, see above... :/ ).
| [reply] [Watch: Dir/Any] |
|
Re: Net::SSH::Perl doesn't like long commands
by syphilis (Archbishop) on Jun 10, 2013 at 14:01 UTC
|
Net::SSH::Perl doesn't like long commands
Net::SSH::Perl has a history of not being user-friendly. Fer chrissake just use one of salva's SSH modules - whichever one is right for your OS , and ask if you don't know which one that is. (salva is far too modest to state that explicitly, but I'm not bound by any such constraints.)
I mean no offence to the current maintainer (yes, it apparently now has one) of Net::SSH::Perl, but a module that contains the word "Perl" in its name yet has so many C-extensions as pre-requisites, is surely trying to sell itself on false pretences.
Cheers, Rob | [reply] [Watch: Dir/Any] |
|
I am not so modest. The thing is more on the I-am-tired-of-recommending-my-modules side :-)
My usual recommendation is to go for Net::OpenSSH if you are on a Linux/Unix box and Net::SSH2 (currently being maintained by Rafael Kitover) if you are on Windows.
Net::SSH::Any is supposed to provide an unified interface to both modules but it is still a work in progress. Though, it is already been used, and what it does, it does it right, mostly!
| [reply] [Watch: Dir/Any] |
|
and Net::SSH2 (currently being maintained by Rafael Kitover) if you are on Windows
And many thanks to Rafael for that module - I'm on MS Windows, and that's the precise module I use. (Of course, I use it via Net::SSH2::Foreign::Backend::Net_SSH2 ... not sure where *that* module comes from ;-)
Cheers, Rob
| [reply] [Watch: Dir/Any] |
|
and Net::SSH2 (currently being maintained by Rafael Kitover) if you are on Windows
And many thanks to Rafael for that module - I'm on MS Windows, and that's the precise module I use. (Of course, I use it via Net::SSH2::Foreign::Backend::Net_SSH2 ... not sure where *that* module comes from ;-)
UPDATE: Ooops ... I'm confusing SFTP and SSH2, now. Probably time for a nap;-)
Cheers, Rob
| [reply] [Watch: Dir/Any] |
Re: Net::SSH::Perl doesn't like long commands
by hdb (Monsignor) on Jun 10, 2013 at 11:24 UTC
|
- Have you tried to issue the command in an interactive shell? Will it also work for 20000 and fail for 50000?
- What is the exact number that makes it fail? Try around 32768 which is the only power of two in the range of 20000 to 50000.
| [reply] [Watch: Dir/Any] [d/l] |
|
- Issuing the command in an interactive shell works fine.
- The script fails when length($cmd) is > 23117.
| [reply] [Watch: Dir/Any] |
|
With $host as "localhost", the script works (but fails sshing to an identical machine).
| [reply] [Watch: Dir/Any] |
Re: Net::SSH::Perl doesn't like long commands
by renormalist (Sexton) on Aug 09, 2013 at 22:46 UTC
|
I just uploaded v1.36 to CPAN which contains several bugfixes with longer history. Please try if your problem is covered.
Net::SSH::Perl is in maintenance mode. I accept patches
but can't dive into debugging on my own.
Kind regards,
Steffen
| [reply] [Watch: Dir/Any] |