2012-03-28 66 views
-2

我正在嘗試使用系統命令從遠程服務器調用帶有標誌的perl腳本。當我發出命令時,由於某些奇怪的原因,我的最後兩個標誌被忽略。有些人可以給我提供一些指導。提前致謝!!!!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'\""); 

錯誤信息 無法確定網絡服務器的唯一端口。 請檢查您的設置,然後重試。正在中止... -bash:第1行:-port:8284:command not found -bash:line 2:-cert:cert.com:command not found

+2

我知道這可能是演示代碼,但請注意 - 您將未經驗證的,未轉義的用戶提供的輸入傳遞到遠程計算機上的根shell。 (你自己的子shell也有風險。)請看列表或間接對象調用'system()'並列出[根據文檔](http://perldoc.perl.org/functions/system.html )。或者,'quotemeta()'或'\ Q'比裸插值要好。 – pilcrow 2012-03-28 13:35:42

+0

[Perl腳本中的XML編輯]的可能重複(http://stackoverflow.com/questions/9877485/xml-editing-inside-a-perl-script) – 2012-03-28 18:47:22

+0

@per docs:'quotemeta'用於常規表達式,而不是殼牌報價。 – salva 2012-03-29 11:02:14

回答

6

You $ webserver and $ port variables are ending with換行符「\ n」。使用chomp功能。

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

謝謝你工作完美 – Badboy 2012-03-28 13:28:45

1

使用sudo的正確,然後Net::OpenSSH處理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的將採取適當的引用一切照顧。