【问题标题】:check_nrpe put $ at end of check stringcheck_nrpe 将 $ 放在检查字符串的末尾
【发布时间】:2014-03-11 01:31:24
【问题描述】:

我的 powershell nagios 脚本有问题,该脚本安装在 MS Windows Server 2008 64 位上,带有 NRPE_NT 守护进程。

我已经声明了这样的命令:

command[check_files]=cmd /c echo C:\nrpe\libexec\check_file.ps1 $ARG1$; exit($lastexitcode) | powershell.exe -command - 

我已将 ExecutionPolicy 设置为不受限制

我已重新启动 NRPE_NT 服务并在控制台上声明命令,如下所示:

$USER1$/check_nrpe -H $HOSTADDRESS$ -t 60 -c check_files -a $ARG1$

现在,为什么我在本地运行它,效果很好:

C:\>cmd /c echo C:\nrpe\libexec\_file.ps1 C:\nrpe; exit($lastexitcode)| powershell.exe -command -
No file/s present with this string

但如果我通过 check_nrpe 运行它,我会收到以下输出:

'-' 是用 -Command 参数指定的:不允许使用 -Command 的其他参数。

在调试模式下,在 NRPE.log 上我可以看到:

运行命令:cmd /c echo C:\nrpe\libexec\check_file.ps1 C:\nrpe; 退出($lastexitcode) | powershell.exe -command - $

命令完成,返回码 0

为什么用这种方式,check_nrpe 在字符串末尾添加一个美元字符($),使整个控件脱轨?

提前致谢

【问题讨论】:

    标签: powershell nagios dollar-sign


    【解决方案1】:

    我不确定这是否会对您的情况有所帮助,但我只是在我的环境中发现了一些导致类似情况的东西。这是我的 NRPE 命令配置:

    command[foo]=grep file '^pattern$'
    

    一切都很好,直到我想在 '^pattern$' 参数之后添加另一个参数...这个新参数(在命令行末尾)会在末尾附加一个额外的 $

    似乎 NRPE 要求 $ 被转义,否则它认为它是一个变量引用并用它做奇怪的事情。我期望引用会使其不需要转义,但是 NRPE 的配置文件不遵循 shell 样式的引用规则。因此,将我的 NRPE 配置更改为此解决了我的问题:

    command[foo]=grep file '^pattern$$'
    

    注意修改后的 NRPE 命令定义中的双 $$

    【讨论】:

      猜你喜欢
      • 2013-11-12
      • 1970-01-01
      • 2014-11-22
      • 1970-01-01
      • 1970-01-01
      • 2014-08-09
      • 1970-01-01
      • 2023-01-27
      • 1970-01-01
      相关资源
      最近更新 更多