tags:

views:

11

answers:

2

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

+1  A: 

Make the cron jobs look for a flag (file) under /var/run, then write an initscript that sets or resets that flag.

Ignacio Vazquez-Abrams
ignacio...i am total unix noob..could you give me an example of the script.
Unixnewbie11
A: 

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

poolie