tags:

views:

412

answers:

2

I'm writing a Perl script that is to be run on a PC networked with a computer running Linux. The script must give input to, and receive results from, a set of shell scripts on the Linux machine. I'm able to copy the input files from the PC and even invoke a Perl script on the Linux machine, but when that script attempts to run the .sh files via:

 system("./shell_script.sh");

It prints the following error:

 '.' is not recognized as an internal or external command, operable program or batch file.

Which I take to mean it's trying to execute the .sh files under Windows. So is there any way to get the PC to tell the Linux box, "hey, buddy, run this yourself"?

Thank you.

+4  A: 

I think you want to use something like Net::SSH or Expect to login into the Linux machine and run the shell script. The system() runs on the local machine; it's not a way to send commands to a remote machine.

brian d foy
+5  A: 

You can use Net::SSH::Perl to run the commands/scripts on remote machine:

use warnings;
use strict;

use Net::SSH::Perl;

my $command = "command";
my $host = "host";
my $user = "username";
my $pass = "password";

my $ssh = Net::SSH::Perl->new( $host );
$ssh->login( $username, $pass );
my($stdout, $stderr, $exit) = $ssh->cmd( $command );

print $stdout;
Space