Trigger a command upon every `crontab -e` edit

1

We are using a shared Linux server account where as everyone comes and edits the crontab. Usually we take a backup like this

crontab -l > `date +\%Y-\%m-\%d\_\%H:\%M:\%S.txt`

Is there an elegant way to trigger this command automatically upon every successful edit by crontab -e ?

nehemiah

Posted 2015-06-16T06:51:41.170

Reputation: 259

Answers

1

You can use inotifywait, which resides in a package called inotify-tools.

The command might be something like

   while inotifywait -e close_write /path/to/file/ToWatch ; do /path/to/executable/script; done 

Just remember to make the script to be executed, containing the command you wrote, executable.

MariusMatutiae

Posted 2015-06-16T06:51:41.170

Reputation: 41 321