wilko has asked for the wisdom of the Perl Monks concerning the following question:

Hi there,

I need a way of initiating a command from a server on a client node and returning the results by way of some exit code so that I can handle the event in a proper way. Up to now, i've been doing this in a shell but that's unreliable and I don't get to see what really happened on the client side. I tried installing Net:SSH from CPAN but the list of dependencies are endless. I also tried Net::SSH2 which has far fewer dependencies but when trying to 'make' the package, it complained about "libssh2.so: undefined reference to dlerror" amongst other similar errors. So, my question I guess is twofold:

1) Am I going about this in the correct way and if so
2) Is Net:SSH2 the way to go?

Many thanks in advance
John

Replies are listed 'Best First'.
Re: Running remote commands (Net::SSH2)
by almut (Canon) on Dec 22, 2009 at 13:27 UTC
    Is Net:SSH2 the way to go?

    You'll probably get different recommendations from different people... but personally I've so far had good results with Net::SSH2 in cases where I couldn't use the system ssh. In other words, I wouldn't give up right away with your attempts to install it.

    As to the "libssh2.so: undefined reference to dlerror" error, undefined reference problems are often caused by mismatching versions of libraries.  It would help us (to help you) if you posted an exact description of what you did, the verbatim error message in the context where it appeared, the versions of libs/module, the OS you're using, etc.

      Hi and thanks for your response. Here's what I've got

      > uname -a
      Linux 2.4.21-37.ELsmp #1 SMP Wed Sep 7 13:28:55 EDT 2005 i686 i686 i386 GNU/Linux

      1. Downloaded Net-SSH2-0.28 from CPAN (has dependencies on openssl and libssh
      2. Downloaded and installed openssl-0.9.8l from http://www.openssl.org. All worked OK
      3. Downloaded libssh2-1.2.2 from http://www.libssh2.org/
      4. Untarred and then:

      ./configure --with-libssl-prefix=/usr/local/ssl (seemed to go through fine)
      make

      This is where it goes wrong. It runs through and exits with this:

      /bin/sh ../../libtool --tag=CC --mode=link gcc -g -O2 -o ssh2 ssh2.o ../../src/libssh2.la
      libtool: link: gcc -g -O2 -o .libs/ssh2 ssh2.o ../../src/.libs/libssh2.so -L/usr/local/ssl/lib -lssl -lcrypto -lz -Wl,-rpath -Wl,/usr/local/lib
      ../../src/.libs/libssh2.so: undefined reference to `dlerror'
      ../../src/.libs/libssh2.so: undefined reference to `dlclose'
      ../../src/.libs/libssh2.so: undefined reference to `dlopen'
      ../../src/.libs/libssh2.so: undefined reference to `dlsym'
      collect2: ld returned 1 exit status
      make2: *** ssh2 Error 1
      make2: Leaving directory `/tmp/libssh2-1.2.2/example/simple'
      make1: *** all-recursive Error 1
      make1: Leaving directory `/tmp/libssh2-1.2.2/example'
      make: *** all-recursive Error 1
      Any guidance greatly appreciated. John
        /bin/sh ../../libtool --tag=CC --mode=link gcc -g -O2 -o ssh2 ssh2 +.o ../../src/libssh2.la libtool: link: gcc -g -O2 -o .libs/ssh2 ssh2.o ../../src/.libs/libssh +2.so -L/usr/local/ssl/lib -lssl -lcrypto -lz -Wl,-rpath -Wl,/usr/loca +l/lib ../../src/.libs/libssh2.so: undefined reference to `dlerror' ../../src/.libs/libssh2.so: undefined reference to `dlclose' ../../src/.libs/libssh2.so: undefined reference to `dlopen' ../../src/.libs/libssh2.so: undefined reference to `dlsym'

        Looks like a problem with libdl not having been found during ./configure, so that the required -ldl is missing from the link command  (the dl library implements dlopen etc. which are used for run-time dynamic linking of shared libs).

        Maybe check

        • if you actually have the lib (would typically be in /lib or /lib64 or /usr/lib or /usr/lib64, e.g. /lib/libdl.so.2)
        • what the configure output has to say (--> "checking for dlopen ...", or some such)
        • if the link command succeeds if you manually issue it with -ldl added (from the directory where ssh2.o is), i.e.
          $ gcc -g -O2 -o .libs/ssh2 ssh2.o ../../src/.libs/libssh2.so -L/usr/l +ocal/ssl/lib -ldl -lssl -lcrypto -lz -Wl,-rpath -Wl,/usr/local/lib
        From the output it looks like it's missing the -ldl flag, pulling in the dynamic linker lib. Could try that command with -ldl and see what you get. Looks like it should work after that to me.
Re: Running remote commands (Net::SSH2)
by zentara (Cardinal) on Dec 22, 2009 at 13:55 UTC
    Is Net:SSH2 the way to go?

    ...yes....it is the module of choice

    it complained about "libssh2.so: undefined reference to dlerror" amongst other similar errors.

    ...that probably means you don't have the libssh2 lib installed properly..... you may need to install whatever your distro calls the "development libs for SSH2"..... or you may need to check your version numbers....Net::SSH2 requires a basic libssh2 level.... make sure you have that compatibility

    ...also if you google for "libssh2.so: undefined reference to dlerror"..... you may find a fix for your linux distribution

    ...the most sure fireway to fix the problem, is to download the latest libssh2 and install it..... when and if it goes in problem free.... then retry the Net::SSH2 install


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku
      Hi and thanks for your reply. I thought the whole point of compiling/installing this package was to install the libssh2.so (amongst other things)....so it can't be on my system as the Make fails.....

      ...or am i missing the point?

      Regards
      John
        am i missing the point?

        ....kind of, yes....... the libssh2 that we talk about is the c based library .... see ssh and ssh2

        ... there has been an evolution over the years from the original ( but problemsome) SSH to SSH2..... they have separate c libs that get installed at the system level..... the perl Makefile is failing because it is NOT finding that lib

        From the Net::SSH2 perl module's README file

        Net::SSH2 is a perl interface to the libssh2 (http://www.libssh2.org)

        once you get that lib installed, try to rebuild the perl module....if it fails again, then come back with the new error message :-)

        .... fwiw, you may not even have ssh2 available to you on the computer you have, if it's yours, the install the libs from the libssh2.org, AND there are many other ways to access your system's ssh capabilities... find out what they are


        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku
Re: Running remote commands (Net::SSH2)
by salva (Canon) on Dec 22, 2009 at 14:45 UTC
    As you are in an Unix box, you could also use Net::OpenSSH.
      use Net::OpenSSH; my $ssh = Net::OpenSSH->new('repository'); $ssh->error and die "Can't ssh to $host: " . $ssh->error;
      when running this, I get

      ssh: illegal option -- M

      with $ssh->error revealing..."unable to establish master SSH connection: ssh master exited unexpectedly"

        You have to ensure you have recent version of OpenSSH installed on the machine.

        What do you get when you run...?

        $ ssh -V