2014-01-22 220 views
0

我使用這個命令罰款:通過SSH遠程運行本地腳本,同時通過arguements

ssh [email protected] 'bash -s' -- < /usr/local/nagios/libexec/check_ssh_mem.sh 

我不喜歡那個劇本的結果,因此要使用perl腳本來代替,而這一點:

ssh [email protected] 'perl -s' -- < /usr/local/nagios/libexec/check_mem.pl 

check_mem.pl v1.0 - Nagios Plugin 

usage: 
    check_mem.pl -<f|u> -w <warnlevel> -c <critlevel> 

options: 
-f   Check FREE memory 
-u   Check USED memory 
-C   Count OS caches as FREE memory 
-w PERCENT Percent free/used when to warn 
-c PERCENT Percent free/used when critical 

正如您所看到的,我從腳本中獲得適當的反饋。我想將-f,-w和-c變量傳遞給它,但在嘗試這樣做時會出錯。

+0

什麼是錯誤?我懷疑你沒有引用腳本的路徑和你的參數被送到ssh。 – user3183018

回答

0

man perlrun說:

Upon startup, Perl looks for your program in one of the following places 
... 
3. Passed in implicitly via standard input. This works only if there are 
    no filename arguments--to pass arguments to a STDIN-read program you must 
    explicitly specify a "-" for the program name. 

所以,你可以使用這個:

ssh [email protected] 'perl - -f -u -C' -- < /usr/local/nagios/libexec/check_mem.pl 

的參數後 - 被傳遞給正在運行的腳本。

您不需要-s參數 - 我假設您從原始bash實現中複製了該參數,但-s對perl有不同的含義。

+0

這很好!非常感謝你...這樣一個簡單的修復:) – BanditBBS

相關問題