如何设置一个系统来告诉我 cron 作业是否运行正常?
这更多的是一个“通用架构”问题。如果您有一个定期运行的 cron 作业(甚至是 Windows 计划任务),那么让它向您发送一封电子邮件/短信表明一切正常,这有点简单,但是当一切正常时我如何得到通知不好吗?基本上,如果作业没有在预定时间运行,或者 Windows / Linux 有自己的一组挂起阻止任务运行......?
只是寻求以前遇到过这种情况的人的想法并提出有趣的解决方案......
This is more of an "general architecture" problem. If you have a cron job (or even a Windows scheduled task) running periodically, its somewhat simple to have it send you an email / text message that all is well, but how do I get informed when everything is NOT okay? Basically, if the job doesn't run at its scheduled time or Windows / linux has its own set of hangups that prevent the task from running...?
Just seeking thoughts of people who've faced this situation before and come up with interesting solutions...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我过去这样做的一种方法是简单地放在每个脚本的顶部(例如
checkUsers.sh
):然后使用
find
定期运行另一个作业code> 来查找tmp/lastrun
中超过一天的所有“标记”文件。您可以调整时间,使用
/tmp/lastrun/hour/
和tmp/lastrun/day/
来分隔具有不同计划的作业。请注意,这不会捕获从未运行的脚本,因为它们永远不会为
find
创建初始文件。为了缓解这种情况,您可以:而且,如果您的 cron 作业不是脚本,请将
touch
直接放入crontab
中:验证简单的
find
脚本比验证简单得多验证您的每一项cron
作业。A way I've done it in the past is to simply put at the top of each script (say,
checkUsers.sh
):then have another job that runs periodically that uses
find
to locate all those "marker" files intmp/lastrun
that are older than a day.You can fiddle with the timings, having
/tmp/lastrun/hour/
andtmp/lastrun/day/
to separate jobs that have different schedules.Note that this won't catch scripts that have never run since they will never create the initial file for
find
-ing. To alleviate that, you can either:And, if your cron job is not a script, put the
touch
directly intocrontab
:It's a lot easier to validate a simple
find
script than to validate every one of yourcron
jobs.