I have an application that is using Net::SSH::Perl to login to hosts and collect data. It has been working fine on all the unix/linux hosts that we have, but now I'm extending it to get data from windows boxes using the cygwin ssh server, and although it seems to be able to login to the windows machines fine, running commands on those machines fails.

Minimal test case script

use Net::SSH::Perl; my($hostname,$username,$password,$debug) = @ARGV; my $ssh = Net::SSH::Perl->new( $hostname, protocol => '2,1', debug => $debug, ); $ssh->login($username,$password); my($out,$err,$ext) = $ssh->cmd("echo LOGINSUCCESSFUL"); print "out=$out err=$err ext=$ext\n";

Linux server output

% ./test.pl linux-host root password Use of uninitialized value in concatenation (.) or string at ./test.pl + line 16. out=LOGINSUCCESSFUL err= ext=0

Windows server output

% ./test.pl windows-host Administrator password Use of uninitialized value in concatenation (.) or string at ./test.pl + line 16. Use of uninitialized value in concatenation (.) or string at ./test.pl + line 16. out= err= ext=255

Using a command-line client

Using the command line ssh client works fine for both hosts

% ssh -2 root@linux-host "echo LOGINSUCCESFUL" root@linux-host's password: LOGINSUCCESFUL % ssh -2 Administrator@windows-host "echo LOGINSUCCESFUL" Administrator@windows-host's password: LOGINSUCCESFUL

Notes

When turning debugging on, the debug output looks identical (with the exception of host names and OpenSSH version numbers). I've also tried specifying the full path to echo which doesn't have any effect. The OpenSSH version on the linux server I tested is 3.1p1 (although the application as it is currently in production runs against many different implementations and versions of ssh on linux, hpux, and solaris hosts), and the OpenSSH version on my windows test host is 3.8p1.

I've found that the one thing I can do which does make this work is to change the protocol specification from 2,1 to 1,2. This has serious impact on performance however, as using protocol 1 means that a new connection is created every time that cmd() is called, and this application may call it hundreds of times for a given host. I also don't have the option of only changing the protocol for the windows hosts, as I don't have any way to identify in advance what the host is running.

Anybody have any additional ideas on how to get this to work with a cygwin server using protocol version 2?


We're not surrounded, we're in a target-rich environment!

In reply to Net::SSH::Perl client fails to run commands on cygwin ssh server? by jasonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.