1755678 Members
3834 Online
108837 Solutions
New Discussion юеВ

cronjob question?

 
SOLVED
Go to solution
Ridzuan Zakaria
Frequent Advisor

cronjob question?

Hi,

How do I schedule a job to run every third Monday of the month?

Thanks.
quest for perfections
5 REPLIES 5
Alex Lavrov.
Honored Contributor

Re: cronjob question?

I don't think it's possible with cron.

You can specify weekday and month day, but not both. But you can write custom script that run monday and check if it's third monday of the months and if yes it runs it.
I don't give a damn for a man that can only spell a word one way. (M. Twain)
Pete Randall
Outstanding Contributor

Re: cronjob question?

You don't. You schedule it to run every Monday and determine in the script itself if the day of the month falls between 15 and 22.


Pete

Pete
Jean-Luc Oudart
Honored Contributor

Re: cronjob question?

Similar question (for a different day)

see thread
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=827914

Regards
Jean-Luc
fiat lux
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: cronjob question?

Cron by itself can't do this. You need to schedule the cronjob to run every Monday and then the script itself needs to test whether or not this is the 3rd Monday of a given month. The easist solution is caljd.sh. I'll assume that you install the attached script in /usr/local/bin

#!/usr/bin/sh

export PATH=${PATH}:/usr/local/bin

if [[ $(caljd.sh -N) -eq 3 ]]
then
echo "It's the 3rd Monday; do your thing"
else
exit 0
fi

Invoke as caljd.sh -u for full usage and examples.
If it ain't broke, I can fix that.
Ridzuan Zakaria
Frequent Advisor

Re: cronjob question?

Thanks. I used solution provided by Clay.
quest for perfections