sshpass命令用输入参数运行shell脚本

问题描述:

我在perl脚本中使用以下命令来运行带有位于不同服务器的特定文件夹中的输入参数的shell脚本。sshpass命令用输入参数运行shell脚本

system('sshpass -p password ssh [email protected] "cd /folder1/fol2; ./test.sh $param1 $param2;"'); 

但似乎输入参数没有得到考虑。任何人都可以帮忙吗?

+3

变量不单引号内插值。 – stevieb

+0

谢谢队友!我终于使用了另一个shell脚本来执行ssh,并使用系统命令从我的perl中调用了相同的脚本,并且工作正常! – GSG

手工报价是棘手,让perl的为你做它:

use Net::OpenSSH; 
my $ssh = Net::OpenSSH->new('[email protected]', password => $password); 
$ssh->system('cd', '/forlder1/fol2', \\'&&', './test.sh', $param1, $param2) 
    or $ssh->die_on_error("Command failed"); 
+0

我无权安装软件包。但最终能够通过调用另一个shell脚本来实现。 – GSG