1748053 Members
4951 Online
108758 Solutions
New Discussion юеВ

Is today a holiday?

 
SOLVED
Go to solution
Greg White
Frequent Advisor

Is today a holiday?

I can't think of an easy way to do this but maybe someone has an idea. Monday is Memorial Day and that is a company holiday. I have several routine tasks that I would like not to run on holidays. Does anyone know of a way within a script to tell if today (current date) is a holiday or not?

Points for all good suggestions.

TIA, Greg
I know how to do it in pascal.
6 REPLIES 6
Craig Rants
Honored Contributor

Re: Is today a holiday?

There is a file used by system accounting called /etc/acct/holidays, you may be able to reference that in your script. You could look at how system accounting uses that file.

GL,
C
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Is today a holiday?

Actually this is rather easy using my date hammer (now where's your date nail) caljd.pl.

There is a file that is seldom used anymore called /etc/acct/holidays. The format is rather simple but I bet yours is out of date and hasn't been touched in years. Edit it to make the year, holidays, and day offset correct for the current year.

You don't have toi do this but I suggest that you actually call your file /etc/acct/holidays_2001 and then symbolically link /etc/acct/holidays_2001 to /etc/acct/holidays. The year extension is my convention for caljd.pl but it will work in the current year without it.

Now here's your answer:
#!/usr/bin/sh
if [ $(caljd.pl -h) -ne $(caljd.pl) ]
then
echo "Today is a holiday.!!!"
else
echo "Bummer, I have to work today."
fi

caljd.pl -u will give full usage.

Regards, Clay



If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Is today a holiday?

Hi again:

If you like, you can instead use the shell/awk equivalent, 'caljd.sh'. The options and usage are exactly the same; where you see caljd.pl in the above example substitute caljd.sh.

You could also play around with the date '+%j' format and then parse the holidays file but which do you think is easier.

By the way, a good way to determine the offsets for the holidays file is to do this:

caljd.sh 1 1 2002 - Julian Day of Jan 1
caljd.sh 7 4 2003 - Julian Day of July 4
Subtract the July 4th JD from Jan 1st JD and add 1 to the result and that is your offset for the /etc/acct/holidays file.

Regards, Clay
If it ain't broke, I can fix that.
Greg White
Frequent Advisor

Re: Is today a holiday?

Hi Clay,

I found the /etc/acct/holidays file. I think this is just a typo on your part but did you mean 7 4 2002 instead of 7 4 2003? And did you mean soft link /etc/acct/holidays_2002 to /etc/acct/holidays instead of _2001?

Otherwise, your solution looks great!

Thanks for your help, Greg.

I know how to do it in pascal.
A. Clay Stephenson
Acclaimed Contributor

Re: Is today a holiday?

Sorry about that Greg. My advanced one-finger 'hunt-and-peck' typing technique seems to have gotten me again. It works almost as well on my spelling. I seem to able to think orders of magnitude faster than I can type.

Regards, Clay
If it ain't broke, I can fix that.
Jeff Schussele
Honored Contributor

Re: Is today a holiday?

CalMan to the rescue again!
Although he tripped on the rug on the way in....
But another job well hammered.

Sigh...I just wish I could script half as well as that.....and Perl to boot....
See - there's a reason some wear salad & most don't.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!