Operating System - HP-UX
1821247 Members
3017 Online
109632 Solutions
New Discussion юеВ

cron - running job on second Tuesday

 
Biren
Occasional Contributor

cron - running job on second Tuesday

I need to run few jobs on 2nd Tuesday of the month and few on 4th Tuesday

How do i do this in cron?

Thanks
3 REPLIES 3
Pete Randall
Outstanding Contributor

Re: cron - running job on second Tuesday

Set the cron job to run on Tuesday and have the script check to see if the day of the month falls between 7 and 14 or set cron to run the job between 7 and 14 and have the script check to see if the day is Tuesday.


Pete

Pete
Patrick Wallek
Honored Contributor

Re: cron - running job on second Tuesday

You don't directly. Cron is not smart enough itself to figure that out.

You will have to build some intelligence into your scripts to figure that out.

The 2nd Tuesday of the month could be anywhere from the 8th to the 14th. So what you should do is run the script every Tuesday and if the date is somewhere between the 8th and 14th of the month, then allow the script to run, otherwise exit.

Use the same logic for the 4th Tuesday, which could be anwhere from the 22nd to the 28th of the month.
A. Clay Stephenson
Acclaimed Contributor

Re: cron - running job on second Tuesday

Cron by itself can't do this. You need to make a crontab entry to spawn the job every Tuesday and then let the job itself determine if this is the 2nd (or 4th) Tuesday. Let's see, this is a date problem. I wonder what I'll use?

Your croned script should look something like this:

if [[ $(caljd.sh -N) -eq 2 ]]
then
echo "2nd Tuesday; do your thing"
else
# it ain't; do nothing
exit 0
fi

Invoke the attached caljd.sh script as caljd.sh -u for full usage and examples.

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