How to make a script run at e.g. 16:00 every last thursday of the month using gnome-schedule or cron?
Asked
Active
Viewed 2.0k times
11
-
0 16 * * 4 test $(date +%m) -ne $(date -d 7days +%m) && export DISPLAY=:0 ; scriptfile – Kevin Jan 23 '18 at 18:25
2 Answers
2
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.

devav2
- 36,312
-
-
1
-
-
but then.. look at july 2014 :) Sorry, just kidding.. The question is solved. Thanks again. – user73331 Nov 09 '12 at 07:20
-
-
btw if the pc is off will this job work when I switch it on? Will anacron perform this task? – user73331 Nov 09 '12 at 11:42
-
Cron doesn't run when the system is switched off. Anacron can perform this task where your system doesn't need to run like a server 24x7 – devav2 Nov 09 '12 at 14:44
-
-
9From
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 -
When last day of month is Wednesday February 28th I think this script breaks. – WinEunuuchs2Unix Jan 26 '17 at 18:11
-
7This 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 05:36
-
Warning: crontab.guru says that this will run "At 16:00 on every day-of-month from 24 through 31 AND on Thursday." (as others have already said) – Tom Mar 26 '21 at 07:18
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

MGP
- 121