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

Hello GURU's it has been awhile that I have needed such great direction, but my current issue has me stumped.

I am looking to use Net::SSH::Perl to remote into host and run a wget command to download a package on the remote host in question. I can seem to get all my commands to run on the remote host, but WGET seems to fail:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Net::SSH::Perl; my $host = '192.168.x.x'; my $user = 'user'; my $pw = 'pass'; my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pw); ## THIS SECTION FAILS ## $ssh->cmd("cd /var/tmp"); $ssh->cmd("wget -c -np -r -nH --cut-dirs=1 --reject \"index.html*\" ht +tp://myURL.com/patch/126546-07/"); ########################

If I run the following, it completes as expected:

 $ssh->cmd("cd /var/tmp; hostname > host.dat");

If I try the same with ; seperated WGET calls, nothing seems to happen

 $ssh->cmd("cd /var/tmp; wget -c -np -r -nH --cut-dirs=1 --reject \"index.html*\" http://myURL.com/patch/126546-07/");

The above shows NOTHING in /var/tmp - though I would expect my downloaded DIR to be there.. I have ran the WGET call on host in question to ensure it supports the WGET package and all works well....

Desired output, would be the script changes to the '/var/tmp' DIR on remote host, then completes the package download in /var/tmp so I then can act on the newly downloaded package.

Replies are listed 'Best First'.
Re: Net::SSH::Perl and WGET
by Perlbotics (Archbishop) on Jan 12, 2015 at 20:28 UTC

    I would try

    • using wget with absolute path (/usr/local/bin/wget etc.),
    • escaping * or using quotemeta on the complete wget command string.
      Thanks for the tip, this has gotten me much closer.. Now once I run the script, everything downloads to remote host, but the system running script just sits there like the script hasn't finished but I see the downloaded DIR on remote host with all files intact: Script Server: $ ./upgradeServices.pl Remote Host: $ ls 126546-07 DO I need a flag to end the WGET once download completes?!
Re: Net::SSH::Perl and WGET
by pme (Monsignor) on Jan 13, 2015 at 08:45 UTC
    Run like this and check the returned values:
    my ($out, $err, $exit) = $ssh->cmd("...

      This may actually be what I need here, as the script downloads now as expected, but script just hangs once download on remote hosts completes.

       my ($out, $stderr3, $exit3,) = $ssh->cmd("/usr/local/bin/wget -c -np -r -nH --cut-dirs=1 --reject index.html* -P /var/tmp 'http://urlHOST/patch/126546-07/'");

      Remote System shows package: co$ ls 126546-07

      Script server shows the script still running, which should have ended after download completed

      $ ./upgradeServices.pl

        What if you add '-v' for verbosity and redirect stdout and stderr into a file on script server?
        my ($out, $stderr3, $exit3,) = $ssh->cmd("/usr/local/bin/wget -v -c -n +p -r -nH --cut-dirs=1 --reject index.html* -P /var/tmp 'http://urlHOS +T/patch/126546-07/' >/var/tmp/download.log 2>&1");
        What can you see in /var/tmp/download.log while the script hangs?