Cron jobs and holidays
Tim Writer
tim-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org
Fri Dec 15 15:29:54 UTC 2006
John Macdonald <john-Z7w/En0MP3xWk0Htik3J/w at public.gmane.org> writes:
> On Thu, Dec 14, 2006 at 01:53:57PM -0500, Neil Watson wrote:
> > How would you ensure that a cron job was not run on a statutory holiday?
> > My current thought was
> >
> > 4 4 * * 2-6 grep `date +%Y%m%d` /etc/holidays 1>/dev/null && my_script
> >
> > Using this method the holidays file is kept manually. Is there a more
> > elegant and automatic way?
>
> The one item of elegance I'd add is to put the test into
> a script so that it can be used in other cron lines (and
> elsewhere too).
>
> 4 4 * * 2-6 today_is_holiday && my_holiday_script
> 4 4 * * 2-6 today_is_holiday || my_normal_script
That's a good idea. Rather than "today_is_holiday", I'd probably call it
just "is_holiday" and provide the date as an optional argument. IOW, the
usage is:
is_holiday [date]
This is easily done at the start of the script like this:
date=${1-`date +%Y%m%d`}
--
tim writer <tim-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org> starnix inc.
647.722.5301 toronto, ontario, canada
http://www.starnix.com professional linux services & products
--
The Toronto Linux Users Group. Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
More information about the Legacy
mailing list