Monit errors when running “check program” for custom script

六月ゝ 毕业季﹏ 提交于 2019-12-06 08:57:20

问题


I am getting syntax errors when I try to check the exit status of a bash script using monit's "check program". If I run the bash script manually, it doesn't error. But if I do monit reload with my monit check program in the config, monit gives me errors.

Here's my current monit .conf file --

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

If I change it to this to make sure monit uses bash to parse the file...

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

Then I get this error

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

Even a test script results in errors -- If I have this in script_to_run.sh:

#!/bin/bash
exit 0

Monit will complain

Error: syntax error 'exit'

If I have this in script_to_run.sh:

#!/bin/bash
echo "hello"

Monit will complain

Error: syntax error 'echo'

For reference -- I have monit 5.4, have followed the "check program" example in the man monit doc, and am able to configure/use monit "check process..." just fine on the same server.


回答1:


ok, fixed. for future reference for anyone reading this -- never put .sh files in /etc/monit.d/

that was the problem. i moved the .sh file to a different directory and everything is fine now.




回答2:


I am using Amazon AMI on AWS cloud. Unfortunately, by default Amazon is shipping older version of Monit - 5.2.5

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

They suggest to install version of monit otherwise. Amazon forum gave this workaround:

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


来源:https://stackoverflow.com/questions/17101842/monit-errors-when-running-check-program-for-custom-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!