Operating System - HP-UX
1846779 Members
4331 Online
110256 Solutions
New Discussion

How to get cronjobs to skip holidays?

 
SOLVED
Go to solution
Derek Card
Advisor

How to get cronjobs to skip holidays?

Hello Experts,

I have a number of cronjobs that run every weekday that I don't want to run on holidays like Good Friday. Is there a file that cron can read to skip holidays? I've looked at the man pages and found nothing.

Thanks,
Derek
8 REPLIES 8
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: How to get cronjobs to skip holidays?

Hi Derek:

That question came up yesterday and the answer is still the same - no, not directly. You should continue to run your cronjob daily BUT it should determine if today is a holiday.

1) Edit and update /etc/acct/holidays. I actually prefer that you create a file /etc/acct/holidays_YYYY and link /etc/acct/holidays to it for the current year.

2) Add something like this to your cron'ed script:

if [[ $(caljd.sh -h) -ne $(caljd.sh) ]]
then
echo "Today is a holiday"
exit 0
fi

If it ain't broke, I can fix that.
Zafar A. Mohammed_1
Trusted Contributor

Re: How to get cronjobs to skip holidays?

Patrick Wallek
Honored Contributor

Re: How to get cronjobs to skip holidays?

Here is the thread from yesterday:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x6e219607df6ed711abdc0090277a778c,00.html

You could probably have used the search function and searched on "cron and holiday" and probably would have gotten some hits.
Pete Randall
Outstanding Contributor

Re: How to get cronjobs to skip holidays?

Derek,

There is a file called /usr/lib/X11/datebook/holidays (hopefully it's on your system) that could be used, with a fairly substantial amount of effort, by a cron script to determine if a give day was a holiday. Then the cron script could proceed or exit depending on the comparison.


Pete

Pete
Pete Randall
Outstanding Contributor

Re: How to get cronjobs to skip holidays?

Clay's (Mr. Date's) solution is probably much better. It requires some manual effort to enter the holidays for each year, but avoids having to deal with things like this (from /usr/lib/X11/datebook/holidays):

"Thanksgiving"
=holiday
4th Thursday in November at 12:00 AM

and the other "floating" holidays.


Pete

Pete
Derek Card
Advisor

Re: How to get cronjobs to skip holidays?

Hi Gang,

Thanks for the amazing quick solutions. It looks like Clay's is the one to beat. Clay, I have one question. You said that you wanted me to create a holidays_YYYY file and link it to holidays. Why?

Thanks,
Derek
A. Clay Stephenson
Acclaimed Contributor

Re: How to get cronjobs to skip holidays?

Hi Derek:

The answer is quite simple. Unlike the cheaper brands which purport to do Julian Days, caljd.sh actually does Julian Days and thus spans thousands of years - leap years and all without an if.

Consider the case of Dec 31, 2003 (New Year's Eve) AND Jan 1, 2004 (New Year's Day) both being holidays. The vanilla UNIX /etc/acct/holidays file was never meant to span years. Caljd.sh first looks to see if there is a holidays_YYYY file for whatever current year its calculation fall in and then look at the plain holidays file.

If it ain't broke, I can fix that.
Derek Card
Advisor

Re: How to get cronjobs to skip holidays?

Thanks everybody. I created a "fake" holiday entry for today and it worked great. I also saw how to use caljd.sh in another thread to calculate the day offsets that the /etc/acct/holidays file expects. That sure beats counting days on a calendar to get the offset values!

Thanks again,
Derek