是否有可能将exec命令的输出redirect到monit日志?
check host example.org with address example.org if failed port 80 protocol http for 2 cycles then exec "/root/cloudflare.py >> /var/log/monit.log"
这似乎不工作:
[EST Mar 6 16:02:19] error : 'example.org' failed, cannot open a connection to INET[example.org:80] via TCP [EST Mar 6 16:02:24] info : 'example.org' exec: /root/cloudflare.py [EST Mar 6 16:02:24] error : 'nginx' process is not running [EST Mar 6 16:02:24] info : 'nginx' trying to restart [EST Mar 6 16:02:24] info : 'nginx' start: /etc/init.d/nginx [EST Mar 6 16:02:24] error : monit: Error reading pid from file '/var/run/nginx.pid'
正如你所看到的那样,它logging了它调用的脚本,脚本确实做了它所要做的事情,但是定向输出不会被logging在日志中。 当然,如果我从cmdline运行。
有两个进程试图追加到同一个日志有问题吗? 或者对于monit exec来说这太多了?
如果monit使用标准的syslog工具,那么看看logger 。 例如,您可以通过pipe道传输命令的输出,并且每行将在相关的日志文件中显示为新消息
echo "Hello Sweetie" | logger
把一个日志消息放到我必须交给CentOS系统的/ var / log / messages中。 我不使用monit,但是应该相当直截了当地找出如何将消息引导到相关的日志。