Operating System - HP-UX
1826339 Members
3889 Online
109692 Solutions
New Discussion

Make jobs not run on holidays

 
SOLVED
Go to solution
Mary Rice
Frequent Advisor

Make jobs not run on holidays

O Great Ones,

July 4th and 5th are company holidays. We have some routine cron jobs that run Monday through Friday. I have updated the system holidays file but I can't find an option for cron to make it skip the holidays in the holidays file. I can change the cron entries this week but I would really like to have it automatically skip holidays. Is there a hidden cron option? I would think that think would be a very common situation.


Thank you,
Mary Rice
8 REPLIES 8
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Make jobs not run on holidays

Hi Mary:

There is no undocumented or hidden (well, if it's hidden it's well hidden) cron option to ignore holidays as defined in /etc/acct/holidays. However, I think we can do this with the date sledgehammer, caljd.sh or caljd.pl. The newest is Version 2.1 but anything after 2.05? will work.

In your scripts add this after making sure that caljd.sh and awk are in your PATH.

if [[ $(caljd.sh) -eq $(caljd.sh -h) ]]
then
echo "Do your stuff"
else
echo "Today is a holiday; skip it"
fi

Basically, the -h will return the next Julian Day that is not a holiday; thus, if these values for today's date differ, today must be a holiday.

This should fix you, Clay

Here's the latest caljd.sh; invoke it as caljd.sh -u for full usage:
If it ain't broke, I can fix that.
Christopher McCray_1
Honored Contributor

Re: Make jobs not run on holidays

hello,

Unfortunately, you will need to adjust the cron entry for this week.


Sorry,

Chris
It wasn't me!!!!
A. Clay Stephenson
Acclaimed Contributor

Re: Make jobs not run on holidays

Here's the perl version of the newest. caljd.pl -u will send full usage to stderr.


You can use either caljd.sh or caljd.pl; the options are exactly the same.

If it ain't broke, I can fix that.
harry d brown jr
Honored Contributor

Re: Make jobs not run on holidays


You need to have your applications/scripts skip the days using a holiday/nowork table. cron just trudges along doing what it is told.

live free or die
harry
Live Free or Die
Mary Rice
Frequent Advisor

Re: Make jobs not run on holidays

Thanks everyone.

I went to a meeting and I had my answers as soon as I got back to my workstation. It looks like it's not quite as easy as I would have liked but I just added these lines to the beginning of my scripts.

if [ $(caljd.sh) -ne $(caljd.sh -h) ]
then
exit 0
fi

I wish there were a way to test it before the July 4th.

Thank you very much,
Mary Rice
A. Clay Stephenson
Acclaimed Contributor

Re: Make jobs not run on holidays

Hi again Mary:

Your scripts should be fine as long as caljd.sh and awk are in your PATH. You might need to do a little exporting before these lines.

Actually you can test now:
1) Temporarily add today's date to your holidays file.
OR
2) Temporarily change $(caljd.sh [-h]) to $(caljd.sh [-h] MM DD YYYY) to test any day you like.

If it ain't broke, I can fix that.
Mary Rice
Frequent Advisor

Re: Make jobs not run on holidays

Duh!!!

Thanks, Clay. My PATH was already set and exported.

Mary Rice
Shannon Petry
Honored Contributor

Re: Make jobs not run on holidays

Well, if you dont like using an external check and want to use your holiday file make your own mods to scripts or a wrapper which checks the holiday file. A wrapper would be something like...
#!/bin/ksh
# make your own hack to remove leading 0's in variables!
HOLIDAY=0
DATE=`date +%d/%m`
LCOUNT=`cat /etc/acct/holidays|grep -v ^\* | wc -l`
LNEED=`expr $LCOUNT - 1`
for LINE in `tail -$LCOUNT /etc/acct/holidays|grep -v ^\*` ; do
TMP=`echo $LINE|awk '{print $1}'`
HD=`echo $TMP|awk -F/ '{print $1}'`
HM=`echo $TMP|awk -F/'{print $2}'`
if [ "${HD}/${HM}" = $DATE ] ;then
echo "holiday today"
else
echo "Bah, another workday"
HOLIDAY=0
fi
done
Then in yyour scrips just have them test for HOLIDAY=1 or 0 in order to run.

There are advances (well used to be anyway) schedulars you can purchase which enhance Cron's abilities like you want. Im too cheap though, so use methods similar to the above.

NOTE: I did not test the above except for grep syntax in ksh and csh (syntax fails in Solaris /bin/sh). Dont complain if it dont work, just giving an example.

Regards,
Shannon
Microsoft. When do you want a virus today?