'Cron job one schedule for 3rd Sunday but different schedule every other day

We have jobs that are scheduled to run 1 time per day - every day We do maintenance every 3rd Sunday of the month.

Up until now every month we have manually adjusted the cron to make the job run a little later in the morning then after maintenance we reset to the desired schedule

I am trying to change cron so that we

  • run at 7:00am every day EXCEPT the third Sunday of the month
  • run at 9:00am only on the third Sunday of the month

the second item I am able to handle

0 13 15-21 * 0

however, the first has me stumped. I thought this would do the job but it will only execute this if the day is between 1-14 or 22-31 but what if the 15th is not Sunday - then it won't run.

0 11 1-14,22-31 * *

How do I tell cron to run a schedule EXCEPT the third Sunday of the month?

There is a large base of guidance on how to limit when a cron runs to a specific window but I haven't found much for how to EXCLUDE a cron from a specific window

******** UPDATE ********

I think I may have come up with an answer - not sure if it is the most efficient but

0 11 1-14,22-31 * 0

0 13 15-21 * 0

0 11 1-14,22-31 * 1-6

The above will

  • run at 11:00 UTC on Sunday if date is between 1-14 or 22-31
  • run at 13:00 UTC on Sunday if date is between 15-21 (3rd Sunday)
  • run at 11:00 UTC Monday through Saturday all month


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source