How to temporarily disable some unix cronjobs using script

I have several cronjobs running daily Monfriday. At times during the holidays, I turn them off manually so that he does not start this day and does not return the next day.

Is there a way to automate this with a script

+7
unix
source share
2 answers

Ignacio suggested something similar in your crontab:

31 1 * * * [ -f /var/run/cron-holiday ] || /usr/local/bin/whatever-command 

then at the beginning of the weekend, as root:

  # touch /var/run/cron-holiday 

and on monday:

  # rm /var/run/cron-holiday 

This is good and simple, but it has a drawback: if you forget to delete the file, your red-scripts will never run again, which may be bad.

An alternative is to have a file specifying the vacation dates and do something like this:

 31 1 * * * grep -q `date -I` /etc/cron-holidays || whatever-command-here 

where the file / etc / cron -holidays contains lines like

 2011-04-01 2011-12-25 

etc.

+8
source share

Do cron jobs to find the flag (file) under /var/run , and then write initscript that sets or resets this flag.

+2
source share