2009-08-31 39 views
0

我正在写一个Perl脚本,它将在运行Linux的计算机上联网的PC上运行。该脚本必须向Linux机器上的一组shell脚本提供输入并从中接收结果。我能够输入文件从PC复制,甚至调用Perl脚本的Linux机器上,但是当该脚本试图通过运行.SH文件:如何使用本地Perl程序在远程计算机上运行shell脚本?

system("./shell_script.sh"); 

它打印出以下错误:

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

我认为它是试图在Windows下执行.sh文件。那么有没有什么办法可以让电脑告诉Linux机器,“嗨,伙计,你自己来运行”?

谢谢。

+0

的示例代码中的一小段给周围的系统调用某些情况下可能是有用的。 – 2009-08-31 21:14:58

+0

好主意,只需一秒钟... – tardcaster 2009-08-31 21:23:08

回答

5

我想你想使用类似Net::SSHExpect登录到Linux机器并运行shell脚本。 system()在本地机器上运行;它不是一种将命令发送到远程机器的方式。

6

您可以使用Net::SSH::Perl到远程计算机上运行命令/脚本:

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; 
相关问题