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

I am having a problem executing a batch file on a remote windows machine running openssh from a linux host. I am using the following test code which works except it never actually executes the batch file after copying the file over to the remote host. Hopefully someone more learned in the ways of the force can help me see the light here.
#!/usr/bin/perl -w use strict; use Net::SFTP; use Net::SSH::Perl; my %credentials = ( user => 'admin', password => 'admin.password'); my @hosts = ('hosta', 'hostb'); my $localfile = 'test.bat'; my $remotefile = 'remote_testfile'; my $local_dir = '/home/admin'; my $remote_dir = 'c:\Documents and Settings\admin'; my $sftp; my $ssh; foreach (@hosts) { $sftp = Net::SFTP->new($_, %credentials) || die; $sftp->put($localfile, "$remote_dir\\$localfile"); $sftp->get("$remote_dir\\$remotefile","$_.$remotefile"); undef $sftp; $ssh = Net::SSH::Perl->new($_) || die; $ssh->login($credentials{'user'}, $credentials{'password'}); my ($out, $err, $exit) = $ssh->cmd("$remote_dir\\$localfile"); undef $ssh; if ($out) { print "$out\n"; } if ($err) { print "Error: $err\n"; } print "Exit code: $exit\n"; }
The batch file contents are equally simple for testing purposes.
$ cat test.bat echo Executing the removal of remote_testfile del remote_testfile

Replies are listed 'Best First'.
Re: Net::SSH::Perl question
by quester (Vicar) on Oct 30, 2008 at 06:40 UTC
    It would help a lot if you showed us the output of your script. I would hazard a quick guess that Windows doesn't like the syntax of:
    c:\Documents and Settings\admin\test.bat
    because of the unquoted spaces. You might try changing the call to $ssh->cmd to
    $ssh->cmd(qq{"$remote_dir\\$localfile"});
      Actually there is zero output aside from exit code 255..