1

I am trying to write a cron schedule to run a job the Thursday before the second Monday in a month. So far I have this

0 0 8 ? * MON#2

But that runs on the second Monday of the month. Is there a way I can go back four days from that time to the previous Thursday?

For example, for September 2016, the second Monday of the month is the 12th of the month. So I would like to schedule this to run the previous Thursday, which would be the 8th of the month.

2
  • Run it every Thursday and check if the day of the month is between 4 & 10, inclusive. "I never could get the hang of Thursdays."
    – Jeff Schaller
    Sep 22, 2016 at 0:11
  • Okay, that makes sense. Thank you for your help with this.
    – ashipma
    Sep 22, 2016 at 0:58

2 Answers 2

2

I don't think you can do that in cron. Maybe with 0 0 * * 4 you should run a script every thursday and in that script, you can check if it is the thursday before the second monday of the month.

0
2
0 0 * * 4 [ $(date +\%d) -ge 4 -a $(date +\%d) -le 10 ] && run-script

Run a crontab entry on Thursdays (here, midnight on any day of the month and any month) that uses test ([) and date to see if the day of the month is 4..10 inclusive. If so, run whatever script you want.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .