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

Currently I'm trying to complete a script that will connect to a linux server and then run a shell script and exit. This will be ran from a MS Windows server. Here is the code sample that I'm currently trying:
use Net::SSH::W32Perl; my $host = 'droz578.com'; my $ssh = new Net::SSH::W32Perl($host, [options]); $ssh->login('user', 'password'); my ($out, $err, $exit) = $ssh->cmd('touch /usr/local/create.txt');
Currently I'm trying to get the files required for making this possible. I run perl -MCPAN -e shell, then run the install Net::SSH::W32Perl and say yes to all prompts and this is what I get:
# Running under perl version 5.008008 for MSWin32 # Win32::BuildNumber 819 # Current time local: Mon Oct 23 17:54:58 2006 # Current time GMT: Tue Oct 24 00:54:58 2006 # Using Test.pm version 1.25 Can't locate Net/SSH/Perl.pm in @INC (@INC contains: blib\lib blib\arc +h C:/Perl/ site/lib C:/Perl/lib .) at blib\lib/Net/SSH/W32Perl.pm line 8. BEGIN failed--compilation aborted at blib\lib/Net/SSH/W32Perl.pm line +8. Compilation failed in require at test.pl line 10. BEGIN failed--compilation aborted at test.pl line 10. NMAKE : fatal error U1077: 'C:\WINDOWS\system32\cmd.exe' : return code + '0x2' Stop. C:\WINDOWS\system32\nmake.EXE test -- NOT OK Running make install make test had returned bad status, won't install without force Failed during this command: VIPUL/Crypt-Random-1.25.tar.gz : make_test NO CHIPT/Math-GMP-2.04.tar.gz : make NO VIPUL/Crypt-RSA-1.57.tar.gz : make_test NO BTROTT/Crypt-DES_EDE3-0.01.tar.gz : make_test NO DPARIS/Crypt-Blowfish-2.10.tar.gz : make NO DPARIS/Crypt-IDEA-1.08.tar.gz : make NO DPARIS/Crypt-DES-2.05.tar.gz : make NO VIPUL/Crypt-Primes-0.50.tar.gz : make_test NO ILYAZ/modules/Math-Pari-2.010708.tar.gz : writemakefile NO 'C:\ +Perl\bin\p erl.exe Makefile.PL' returned status 2304 DBROBINS/Net-SSH-Perl-1.30.tar.gz : make_test NO SCOTTS/Net-SSH-W32Perl-0.05.tar.gz : make_test NO VIPUL/Tie-EncryptedHash-1.21.tar.gz : make_test NO BTROTT/Convert-PEM-0.07.tar.gz : make_test NO SOENKE/String-CRC32-1.4.tar.gz : make NO
Any help would be apperciated. thanks droz578

Replies are listed 'Best First'.
Re: CPAN Net::SSH::W32Perl Problem
by Khen1950fx (Canon) on Oct 24, 2006 at 15:30 UTC
    You need to install pari before you try to install anything else. Then install Math::Pari. I wish there was an easy way to do it, but I'm not aware of one. You can get pari at pari
Re: CPAN Net::SSH::W32Perl Problem
by erbo5212 (Initiate) on Oct 25, 2006 at 02:20 UTC

    Net::SSH::W32Perl is a bit sketchy. Personally I would just use PuTTY to create a public key to put on your server and wrap plink (command line utility in the PuTTY family) to send commands to it over via SSH.

    Using ActivePerl 5.8 I was able to install Net::SSH::Perl and Net::SSH::W32Perl, provided I did not run nmake test during the installation process. Not recommended practice but I could never get it to pass.

    Then I had to remove/modify references to the getpwuid function in the C:\Perl\site\lib\Net\SSH\Perl.pm module, as there is no getpwuid on Windows platforms.

    Using it is also a bit of a trick. Do not expect any command output to return to the client (you) and your script will hang if your command does produce output. Since all you are doing is touching a file, you should be OK.

    my ($out, $err, $exit) = $ssh->cmd('touch /usr/local/create.txt', "\n");

    The "\n" is important. If you are going to run a command that will produce output, pipe it to a file:

    my ($out, $err, $exit) = $ssh->cmd('ls -al > ls_out', "\n");