powershell - check_nrpe将$放在检查字符串的末尾

标签 powershell nagios dollar-sign

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

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

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

我已将ExecutionPolicy设置为不受限制

我已经重新启动NRPE_NT Services并在控制台上声明了命令,如下所示:
$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运行它,我会收到以下输出:

使用-Co​​mmand参数指定了'-':不允许使用-Co​​mmand的其他参数。

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

Running command: cmd /c echo C:\nrpe\libexec\check_file.ps1 C:\nrpe; exit($lastexitcode) | powershell.exe -command - $

Command completed with return code 0



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

提前致谢

最佳答案

我不确定这是否会帮助您解决问题,但是我只是发现环境中的某些原因导致了类似情况。这是我的NRPE命令配置:

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

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

似乎NRPE需要转义$,否则它认为这是一个变量引用,并且对此做了奇怪的事情。我原以为引用会成功,所以不需要转义,但是NRPE的配置文件不遵循shell样式的引用规则。因此,将我的NRPE配置更改为此解决了我的问题:
command[foo]=grep file '^pattern$$'

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

关于powershell - check_nrpe将$放在检查字符串的末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21732760/

相关文章:

powershell - 将字符串拆分为两个数组

android - $ sign in a Text widget,如何在flutter中显示特殊字符?如何在 flutter 中将特殊字符设置为文本小部件

monitoring - Nagios - 无法打开命令文件/usr/local/nagios/var/rw/nagios.cmd' 进行更新

mysql - 慢查询问题 - 得到通知

linux - 如何授予 Nagios 权限以在自定义脚本中运行某些命令?

javascript - Chrome 中的 $ 变量(美元符号)?

python - 运行命令时 $ 是什么意思?

powershell - Invoke-Expression 设计用于什么场景?

powershell - Powershell当前时间减去特定格式的n秒

powershell - 如何获取在 Azure Function 中运行的 Azure PowerShell 模块版本列表?