10

This question already has an answer here:

How to make a script run at e.g. 16:00 every last thursday of the month using gnome-schedule or cron?

marked as duplicate by Pilot6, muru, David Foerster, TheWanderer, waltinator Jan 27 '17 at 8:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 0 16 * * 4 test $(date +\%m) -ne $(date -d 7days +\%m) && export DISPLAY=:0 ; scriptfile – Kevin Jan 23 '18 at 18:25
4

Open crontab (crontab -e)and add this entry.

0 16 24-31 * 4 script_file

You can use this online cron generator.

Hope this helps.

  • Or use this editor. It's a bit more comprehensive. – Glutanimate Nov 9 '12 at 4:20
  • 1
    great, thanks. But it won't run on april 2014 :) – user73331 Nov 9 '12 at 4:27
  • changing it to 24-31 will solve it :) – devav2 Nov 9 '12 at 5:50
  • 5
    From man 8 crontab: The day of a command's execution can be specified by two fields — day of month, and day of week. If both fields are restricted (i.e., aren't *), the command will be run when either field matches the current time. So won't this also be run every Thursday? – Dan Gravell Oct 10 '16 at 10:32
  • 3
    This is completely wrong. This will run on the 24th, 25th,...,31th and every Thursday. See the comment of @DanGravell or IEEE Std 1003.1 – miracle173 Aug 10 '17 at 5:36
2

Faced with the same issue I created a script (cron-last-sunday) to help with this.

Here is a brief example of how easy you can achieve these "peculiar" requirements.

# every first saturday
30 6 * * 6 root run-if-today 1 && /root/myscript.sh

# every last sunday
30 6 * * 7 root run-if-today L && /root/myscript.sh

# every third tuesday
30 6 * * 2 root run-if-today 3 && /root/myscript.sh

Not the answer you're looking for? Browse other questions tagged or ask your own question.