如何从 monit 中的 exec 程序脚本输出 stdout 和 stderr

How to output stdout and stderr from an exec program script in monit

我有一个 python 脚本,我用它来检查某些系统条件以提醒使用 monit。 该脚本在执行期间将大量内容打印到标准输出,我想将其捕获到日志文件中。 我应该如何配置 monit conf 脚本,以便我可以捕获该脚本的 stdout 和 stderr,同时提醒脚本的退出状态。 monit 警报还应包括警报事件的 stdout/stderr。

这是我试过的

#/etc/monit/conf/myprogram.conf

check program my_program with path "/usr/bin/python -u /opt/program/my_program.py > my_prgoram.log 2&>1"
 if status !=0 alert

但我看到 monit 总是认为该程序正在报告 status=0,即使它存在并显示错误代码 1。

我做错了什么?

试试这个:

#/etc/monit/conf/myprogram.conf

check program my_program with path "/bin/bash -c '/usr/bin/python -u /opt/program/my_program.py > my_prgoram.log 2&>1'"
 if status !=0 alert

$MONIT_DESCRIPTION 包含标准错误