当守护进程在几秒后停止写入日志文件时发出警报

当守护进程在几秒后停止写入日志文件时发出警报

如果某个守护进程 (linux) 停止写入其日志文件,我需要发送警报。此守护进程无法正常工作,并且在关闭时不会写入任何内容。

我正在使用 inotify 来观察这个问题。

我看到的是:

inotifywait -e modify -t 10 /usr/local/assp/maillog.txt
Setting up watches.
Watches established.
/usr/local/assp/maillog.txt MODIFY

我创建了这个 cron:

*/1 * * * * inotifywait -e modify -t 120 /usr/local/assp/maillog.txt || echo "Assp stopped" | mail -s "$(hostname) ASSP stopped" [email protected]

我认为这是一段糟糕的代码。还有更好的想法吗?

相关内容