ashok.g has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I have installed Net::SSH2 v0.44 on Perl v5.8.9 built for sun4-solaris-thread-multi using the link

Now I have two different scripts which will finally call same sub routine:
sub SSH_Reference { #print "Starting SSH_REFERENCE......<br>"; ($rip, $rusr, $rpwd) = (shift, shift, shift); chomp($rip, $rusr, $rpwd); my $ssh2 = Net::SSH2->new(); $auth_fail{$rip}="Failed"; #return "Can not connect $rip " unless ($ssh2->connect($rip)); + ## or die "Can not Connect $rip "; #print "$ssh2---$rip----$rusr---$rpwd---<br>"; if ( ! ($ssh2->connect($rip)) ) ## or die "Can not Connect $r +ip "; { print qq{<font color="red"><b> Error: Cannot connect t +o $rip : SSH service Failed </b></font>},$ssh2->error; $eer = 1; return "$eer"; } print "In Progress....<br>"; exit;
One of the scripts printed "In Progress...." but where as other script gave "-43LIBSSH2_ERROR_UNKNOWN(-43)Failed getting banner" error.
,br> Why there is error throwing for other script when running on same machine by passing same parameters? Can you please help me on this?

Thanks,
Ashok.

Replies are listed 'Best First'.
Re: strange Net::SSH2 on Solaris10
by syphilis (Archbishop) on May 29, 2012 at 01:03 UTC
    other script gave "-43LIBSSH2_ERROR_UNKNOWN(-43)Failed getting banner" error

    I suspect that script tries to get the banner (in a way that is unacceptable for your version of libssh2), whereas the other script does not.

    See the Net-SSH2 test script for an example of the correct way to handle the setting/getting of the banner with recent versions of the libssh2 library.
    Which version of the libssh2 library do you have ? It may need updating.

    Cheers,
    Rob
      Rob,

      Thanks for the reply.

      But no errors here:
      bash-3.00# perl testing.pl 1..73 ok 1 - use Net::SSH2; ok 2 - new session isa Net::SSH2 ok 3 - error state clear ok 4 - set banner ok 5 - LIBSSH2_* constants ok 6 - list version match ok 7 # skip version not decimal ok 8 - banner is SSH-2.0-libssh2_1.4.0 ok 9 - poll indefinite ok 10 - poll 1/4 second ok 11 - ->sock is undef before connect To test the connection capabilities of Net::SSH2, we need a test site +running a secure shell server daemon. Enter 'localhost' to use this host. Select host [ENTER to skip]: 192.168.1.98 ok 12 - connect to 192.168.1.98 ok 13 - ->sock isa IO::Socket::INET isa IO::Socket::INET ok 14 - kex method: diffie-hellman-group-exchange-sha1 ok 15 - hostkey method: ssh-rsa ok 16 - crypt_cs method: aes128-ctr ok 17 - crypt_sc method: aes128-ctr ok 18 - mac_cs method: hmac-sha1 ok 19 - mac_sc method: hmac-sha1 ok 20 - comp_cs method: none ok 21 - comp_sc method: none ok 22 - have MD5 hostkey hash ok 23 - have SHA1 hostkey hash Enter username [root]: netcool ok 24 - authenticate: gssapi-keyex,gssapi-with-mic,publickey,password, +keyboard-interactive ok 25 - list matches comma-separated ok 26 - not authenticated yet [user netcool] Password: ok 27 - authenticated via: keyboard ok 28 - authenticated successfully ok 29 - new channel isa Net::SSH2::Channel ok 30 - set blocking ok 31 - not at EOF ok 32 - normal extended data handling ok 33 - merge extended data ok 34 - empty setenv ok 35 - set environment variables ok 36 - verify session ok 37 - set disconnect callback ok 38 - SFTP session isa Net::SSH2::SFTP ok 39 - verify session ok 40 - create directory net_ssh2_1737 ok 41 - stat directory ok 42 - type is directory ok 43 - directory name matches ok 44 - put testing.pl to remote ok 45 # skip - IO::Scalar required ok 46 # skip - IO::Scalar required ok 47 - unlink non-existant file fails ok 48 - got LIBSSH2_FX_NO_SUCH_FILE error ok 49 - rename net_ssh2_1737/testing.pl -> net_ssh2_1737/testing.pl.re +named ok 50 - stat net_ssh2_1737/testing.pl.renamed ok 51 - stat filename matches ok 52 - stat filesize matches ok 53 - opened file isa Net::SSH2::File ok 54 - compare stat and fstat ok 55 - compare fstat % and %$ ok 56 - opened directory isa Net::SSH2::Dir ok 57 - found net_ssh2_1737/testing.pl.renamed ok 58 - opened file isa Net::SSH2::File ok 59 - read '\# THIS LINE WILL BE READ BY A TEST BELOW' ok 60 - unlink net_ssh2_1737/testing.pl.renamed ok 61 - remove directory net_ssh2_1737 ok 62 - close SFTP session ok 63 - exec 'ls -d /' ok 64 - got poll response ok 65 - got input event ok 66 - got result '/' ok 67 - no more lines ok 68 # skip - public key infrastructure not present ok 69 # skip - public key infrastructure not present ok 70 # skip - public key infrastructure not present ok 71 # skip - public key infrastructure not present ok 72 - close channel ok 73 - sent disconnect message

      Thanks,
      Ashok.
        no errors here

        Good - no problems with that version of the libssh2 library. Are you certain that your failing script uses the very same libssh2 library ?

        Next thing to do would be to determine which line of code in your script is producing the error. I don't see anything in the subroutine you posted that should cause that error, so it probably happens before that sub is called.

        Cheers,
        Rob
Re: strange Net::SSH2 on Solaris10
by salva (Canon) on May 30, 2012 at 06:54 UTC
    Are both scripts connecting to the same host as the same user?

    In case the response is yes, then the problem may be caused by some incompatibility between libssh2 and the remote SSH server software.

    If the response is no, then you are looking at the wrong place. There should be some difference between the two scripts that causes them to perform differently.

    From your previous posts, I see that you are trying to mix SSH and threads, it is possible that Net::SSH2 amd libssh2 are not thread safe.

    You may also like to check Net::OpenSSH::Compat::SSH2, an adaptor module for Net::OpenSSH providing the API of Net::SSH2. OpenSSH client is quite more mature than libssh2, and all SSH server software vendors ensure that their products interopetate with it.

      Hi Salva,

      Thanks for your reply.

      Are both scripts connecting to the same host as the same user?

      Yes. That's correct.

      then the problem may be caused by some incompatibility between libssh2 and the remote SSH server software.

      This sub routine works perfectly in Perl 5.8.8 (may be that is ActivePerl) but now it is Perl 5.8.9. Do you think that this might be the cause?

      Thanks,
      Ashok.
        So, both scripts fail under 5.8.9? or are you running one under 5.8.8 and the other under 5.8.9?

        It is very unlikely that the changes between 5.8.8 and 5.8.9 could affect Net::SSH2, but there may be other changes as versions of the module, or the library or of any of its dependencies.

        Who knows! you have not given enough detail.