I am having problems with various ssh modules.
As it turns out, (Thanks syphilis) this is a limit on each write or print call, not the channel itself, so that breaking the writes down into smaller chunks solves the problem.
I have not tried this with Net::SSH::Perl, but the calling mechanismn is different so its hard to see how one would. In fact the reason I had this problem could be seen as being a legacy of the use of Net::SSH::Perl calling mechanism in my code. I have not tried this with any Win32 system, yet.
In this situation stdin and stdout would be binary streams not necessarily containing line feeds.
There is no need for interactivity.
So my first idea was to use Net::SSH::Perl and with some difficulty I installed this on both the Linux and the Windows machine. (Active state perl. )
But the problems mounted up here, and the remote process would hang if the standard input was more than 10631 bytes. This was using Ubuntu 10.04 to a machine running Fedora 9. (I gave up on windows at this stage.) I also tried it to the local machine, Ubuntu 10.04, and the same problem occurred, except at a different and amount, about 32k.
So, I googled.
It seems there was a discussion about this issue or something similar and a patch was published. The patch would not install on my sources, but I was able to make the changes manually. It changed the size at which it happened by a few bytes, but otherwise had no effect. I removed the patch.
The patch was this one here. http://cpanforum.com/threads/873. It sounds like this really is the problem. The solver does not sound to confident about the patch working. BUT, this was a 2005 thread, with the last comment in 2008, are we really saying that Net::SSH::Perl has been broken since 2005 and nobody can fix it ?
Below was my Net::SSH::Perl code, although not the only variant that I had tried. Note that remote commands such as wc, date etc are used for illustration and as examples of remote commands that do and do not use input.
Then I read a comment saying that Net::SSH::Perl was obsolete and Net::SSH2 is the way to go. Hmmph.#!/usr/bin/perl use Net::SSH::Perl; my ($user,$host,$password)=split(/[\@:]/,$ARGV[0]); my $cmd="wc"; my %params=('debug',1 ); my $ssh = Net::SSH::Perl->new($host,%params); $ssh->login($user, $password); my $intext="X" x 10631; # 10631 and bigger fails. # after the patch, +10583 doesnt work, 10582 does. my ($stdout, $stderr, $exit) = $ssh->cmd($cmd,$intext); print "remote output is $stdout\n"; print "remote exit status is $exit\n"; print "remote stderr is $stderr\n";
Like Net::SSH::Perl, Net::SSH2 man page does not state weather or not it runs under windows operating systems, this seems to be left as an exercise for the reader. So far as I could see it did not at first but does now. ( As a side note it would be sooo useful if the documentation clearly stated which operating systems the module runs on and which it does not. )
In this case, the process appears to run but no output is transferred. Here is my (rather scrappy) code:
Strangly it works if instead of using wc, you use the command date (which does not read the input) or if you use perl at the remote end to generate arbitrary strings, again without using the input. I have only tried this on localhost.
Since we have the luxary of a file handle here, I expected to be able use the read function, but I also had trouble with this.
So, my question, Perl Monks is what should I do next. Which modules should I be using, (Perhaps it is none of the above?) and is it really true that both modules are broken ? Or is there something fundamental and stupid wrong with my code?#!/usr/bin/perl # use Net::SSH2; use strict; my ($host,$user,$password); ($user,$host,$password)=split(/[\@:]/,$ARGV[0]); my $cmd; $cmd="wc"; #$cmd="date"; #$cmd="perl -e \"print 'Y'x100000\""; my $ssh = Net::SSH2->new(); print STDERR "ssh created\n"; $ssh->connect($host) or die "Unable to connect Host $! \n"; print STDERR "ssh connected \n"; $ssh->auth_publickey($user, '/home/mark/.ssh/id_rsa.pub', #testing on localhost '/home/mark/.ssh/id_rsa' ) or die "Unable to login $!\n"; print STDERR "ssh authenticated\n"; my $intext="X" x 100000; print STDERR "cmd is $cmd\nintext length is ".length($intext)."\n"; my $chan = $ssh->channel() or die "channel creation failed $!"; $chan->blocking(0); binmode($chan); #$chan->shell(); $chan->exec($cmd); print $chan $intext; my $n=0; # while ($n=read($chan,$buf,512)) # while ($n=$chan->read($buf,512)) #{ # print STDERR "$n bytes read\n"; #} my $exit; while (<$chan>) { print $_; $n+=length($_); } $chan->close; $exit=$chan->exit_status(); print "remote exit status is $exit bytes returned is $n bytes\n";
These seem reasonable and simple things to want to do with Perl, so I cannot see why I am having so much trouble!!
regards,
Mark.
In reply to Net SSH problems by perlinmyveins
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |