为自定义脚本运行“检查程序”时出现Monit错误

时间:2013-06-14 05:44:53

标签: monit

当我尝试使用monit的“检查程序”检查bash脚本的退出状态时,我收到语法错误。如果我手动运行bash脚本,则不会出错。但是如果我在配置中使用我的monit check程序进行monit reload,monit会给我错误。

这是我目前的monit .conf文件 -

check program myscript with path "/etc/monit.d/script_to_run.sh"
  if status != 0 then alert

如果我将其更改为此以确保monit使用bash来解析文件...

check program myscript with path "/usr/bash /etc/monit.d/script_to_run.sh"
  if status != 0 then alert

然后我收到此错误

Warning: Program does not exist: '"/bin/bash /etc/monit.d/script_to_run.sh"'

即使是测试脚本也会导致错误 - 如果我在script_to_run.sh中有这个:

#!/bin/bash
exit 0

Monit会抱怨

Error: syntax error 'exit'

如果我在script_to_run.sh中有这个:

#!/bin/bash
echo "hello"

Monit会抱怨

Error: syntax error 'echo'

供参考 - 我有monit 5.4,已经按照man monit doc中的“check program”示例,并且能够在同一台服务器上配置/使用monit“check process ...”。

2 个答案:

答案 0 :(得分:7)

好的,修好了。对于阅读本文的任何人的未来参考 - 永远不要将.sh文件放在/etc/monit.d/

这就是问题所在。我将.sh文件移动到另一个目录,一切都很好。

答案 1 :(得分:0)

我在AWS云上使用Amazon AMI。不幸的是,默认情况下,亚马逊正在发售旧版Monit - 5.2.5

https://forums.aws.amazon.com/thread.jspa?threadID=215645

他们建议安装monit版本。亚马逊论坛给出了这个解决方法:

sudo yum install -y https://kojipkgs.fedoraproject.org//packages/monit/5.14/1.el6/x86_64/monit-5.14-1.el6.x86_64.rpm
相关问题