Operating System - HP-UX
1833056 Members
2635 Online
110049 Solutions
New Discussion

How to make a cron task holiday aware?

 
SOLVED
Go to solution
David Yandry
Frequent Advisor

How to make a cron task holiday aware?

Hi,

Nobody will be here Monday (Memorial Day) to change backup tapes. Is there a way to have cron not run the tasks on holidays?

TIA, David
8 REPLIES 8
Pete Randall
Outstanding Contributor
James A. Donovan
Honored Contributor

Re: How to make a cron task holiday aware?

Not really, but you could modify your task easily enough to check for the existance of a "holiday" file. You can use cron to create/remove the /tmp/holiday file

ex.

touch /tmp/holiday

if [ -f /tmp/holiday ]; then
exit #...take the day off!
fi
Remember, wherever you go, there you are...
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: How to make a cron task holiday aware?

Somebody always asks this before holidays. A search on "holiday" and "cron" would almost certainly turn up an answer.

The direct answer to your question is "NO"; cron don't know nothing about no holidays. The tasks themselves will have to determine if today is a holiday and, if so, exit.

There is a seldom used file, /etc/acct/holidays that you need to update then caljd.sh can handle the task.

In your croned script:

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

# otherwise continue with task

You will probably need to use caljd.sh to calculate the day offsets for the holidays file. I suggest that you actually create a holidays_2003 file and symbolically link it to the holidays file. Caljd.sh will preferentially use the _YYYY file and you just might need to skip over New Year's eve and New Year's Day. The standard holidays file won't handle that.

You should be able to search and find a copy of caljd.sh (or caljd.pl if you prefer). Make sure that you get version 2.1; it's the latest.

Invoke as caljd.sh -u for full usage and an explanation of the -h switch.




If it ain't broke, I can fix that.
Steven E. Protter
Exalted Contributor

Re: How to make a cron task holiday aware?

Last time this came up I noted that we actually kill the cron daemon with a cron job at a particular time.

Then I have to log in durig the holiday and restart the daemon.

That's hardly fair is it?

What I have done is make the scripts themselves holiday aware.

They have date checking against a holiday list and most of them self terminate on that basis.

cron is stupid, it runs the way you program it. It is the servant of the systems administrator, only as smart as the admin makes it.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Paula J Frazer-Campbell
Honored Contributor

Re: How to make a cron task holiday aware?

David

Why not just leave the tapes in and let the next backup over write them?

Paula
If you can spell SysAdmin then you is one - anon
David Yandry
Frequent Advisor

Re: How to make a cron task holiday aware?

Hi Paula,

That was my first thought but it was shot down as not being ISO 9000 compliant. It seems that if a backup tape is marked 'Monday' it better damn well have only Monday's data on it.

Hi Clay,

You hinted that I could use caljd.sh to set the values in the holidays file. Could you please post an example.

Thanks, David
A. Clay Stephenson
Acclaimed Contributor

Re: How to make a cron task holiday aware?

Okay, I'll give you a hint. I actually have ascript to calculate the offsets. You feed it month, day, and year of the holiday and it spits out the number of days since Jan. 1st of the same year plus 1 - which is the offset value that the holidays file expects.

Here is July 4th, 2003

OFFSET=$(($(caljd.sh 7 4 2003) - $(caljd.sh 1 1 2003) + 1))
echo "Offset: ${OFFSET}"
If it ain't broke, I can fix that.
Suhas_2
Regular Advisor

Re: How to make a cron task holiday aware?

Hi David,
1> If you know the list of holidays in the year, simply create a file in your favourite location, having the dates.
2> In the beginning of your script, just put a simple "if", asking it to check the presence of today's date in the "holiday" file. If today is a holiday, let the script exit there it self.
3> This would be one time job per year, and you can enjoy your holidays without worrying about the scheduled job.
4> This would safe-guard the interest of other scheduled jobs as well.

Hope this helps...

Regards..
Suhas

Never say "Die"