I have few cronjobs running everyday Mon-friday.At times during holidays, i turn them off manually so that it doesnt run that day and turn back on the next day.
Is there a way to automate this using a script
I have few cronjobs running everyday Mon-friday.At times during holidays, i turn them off manually so that it doesnt run that day and turn back on the next day.
Is there a way to automate this using a script
Make the cron jobs look for a flag (file) under /var/run
, then write an initscript that sets or resets that flag.
Ignacio was suggesting something like this in your crontab:
31 1 * * * [ -f /var/run/cron-holiday ] || /usr/local/bin/whatever-command
then at the start of a holiday weekend, as root:
# touch /var/run/cron-holiday
and on Monday:
# rm /var/run/cron-holiday
This is nice and simple but does have the drawback that if you forget to delete the file, your cronscripts will never run again, which could be bad.
An alternative is to have a file listing holiday dates and do something like this:
31 1 * * * grep -q `date -I` /etc/cron-holidays || whatever-command-here
where the /etc/cron-holidays file contains lines like
2011-04-01
2011-12-25
etc