我正在使用此命令:
ssh user@ip 'bash -s' -- < /usr/local/nagios/libexec/check_ssh_mem.sh
我不喜欢该脚本的结果,所以想要使用perl脚本并使用它:
ssh user@ip '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 :(得分:0)
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 user@ip 'perl - -f -u -C' -- < /usr/local/nagios/libexec/check_mem.pl
- 之后的参数将传递给您正在运行的脚本。
你不需要-s参数 - 我假设你从原始的bash实现中复制了它,但-s对perl有不同的含义。