crontab更改时如何获得警报? [英] How to get alert when crontab changes?

查看:85
本文介绍了crontab更改时如何获得警报?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我大约有一打服务器,每个服务器都有crontab,其中的crontab条目为20-50个。我最常见的导致流程失败的原因是有人在修复或修补过程中将cron中的作业注释掉,然后忘了取消注释作业。

I've got about a dozen servers that each have crontabs with anywhere from 20-50 crontab entries. My single most common cause of a process failure is someone commenting out jobs in cron during a fix or patch and then forgetting to uncomment the jobs.

我想做有两点可以解决此问题:

I'd like to do two things to solve this:


  1. 开始使用我们的计划抑制过程,该过程允许用户抑制计划而无需实际触摸crontab。没什么了不起的-只需触摸专用于该过程的目录中的文件即可。该过程会在启动时检查该目录。

  2. 如果crontab与svn中的备份或当前版本不匹配,则执行一个会发出警报的过程。

任何人都可以推荐现有的#2解决方案(在crontab更改时发出警报)?

Can anyone recommend an existing solution for #2 (alert when crontab changes)?

推荐答案

在这种情况下,我建议比较您要拥有的文件和实际文件的哈希值。

In this case i would suggest to compare hashvalues of the file you want to have and the actual file.

只需编写一个小的bashscript即可发送电子邮件通知或创建通知文件或您想要的任何文件,然后让此脚本每x秒/分钟/小时自动运行一次。

Just write a little bashscript that sends out a emailnotification or creates a notification file or whatever you want and let this script be run automatically every x seconds / minutes / hours.

A可能的脚本可能是

if [[ $(md5sum path/to/crontab.backup | cut -d' ' -f1) == $(md5sum /etc/crontab | cut -d' ' -f1) ]]
then
    # send your notification
fi

这是一个非常简单的解决方案,用于检查自上次备份以来文件是否已更改。

This is a very simple solution to check if a file was changed since the last backup was made.

这篇关于crontab更改时如何获得警报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆