perl中的System()

perl中的System(),perl,Perl,我试图使用system命令从远程服务器调用带有标志的perl脚本。当我发出命令时,由于某种奇怪的原因,我的最后两个标志被忽略了。请给我一些指导。提前感谢 #!/usr/bin/perl print "Webserver?\n"; my $webserver = <STDIN>; print "PORT?\n"; my $port = <STDIN>; system("ssh -t <HOST> \"sudo su - root -c '/WebAppSA/

我试图使用system命令从远程服务器调用带有标志的perl脚本。当我发出命令时,由于某种奇怪的原因,我的最后两个标志被忽略了。请给我一些指导。提前感谢

#!/usr/bin/perl
print "Webserver?\n";
my $webserver = <STDIN>;

print "PORT?\n";
my $port = <STDIN>;

system("ssh -t <HOST> \"sudo su - root -c '/WebAppSA/apache/V2.2/install_apache/webmaster.pl -C -name:$webserver -port:$port -  cert:cert.com'\"");
#/usr/bin/perl
打印“Web服务器?\n”;
我的$webserver=;
打印“端口?\n”;
我的$port=;
系统(“ssh-t\”sudo su-root-c'/WebAppSA/apache/V2.2/install\u apache/webmaster.pl-c-name:$webserver-port:$port-cert:cert.com'\”);
错误消息 无法确定web服务器的唯一端口。 请检查您的设置,然后重试。流产。。。 -bash:第1行:-端口:8284:未找到命令
-bash:line 2:-cert:cert.com:command not found

您的$webserver和$port变量以新行字符“\n”结尾。使用chomp函数

my $webserver = <STDIN>;
chomp $webserver;
...
my$webserver=;
chomp$webserver;
...

正确使用sudo,然后处理ssh连接:

my $ssh = Net::OpenSSH->new($host);
$ssh->system(sudo => '/WebAppSA/apache/V2.2/install_apache/webmaster.pl',
                     '-C', "-name:$webserver", "-port:$port", '-cert:cert.com');

Net::OpenSSH将负责正确引用所有内容。

我知道这可能是演示代码,但请小心-您正在将未经验证、未替换的用户提供的输入传递到远程计算机上的根shell。(您自己的子shell也有风险。)请查看使用列表或间接对象和列表调用
system()
。或者,
quotemeta()
\Q
比裸插值更好。可能重复的@per文档:
quotemeta
用于常规表达式,而不是shell引用。@salva,是的,没错。这不是合适的工具。