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
2 Answers
3
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
- 35,738
- 17
- 79
- 82
-
Or use [this editor](http://www.corntab.com/pages/crontab-gui). It's a bit more comprehensive. – Glutanimate Nov 09 '12 at 04:20
-
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](http://pubs.opengroup.org/onlinepubs/007904975/utilities/crontab.html) – miracle173 Aug 10 '17 at 05:36
-
Warning: [crontab.guru](https://crontab.guru/#0_16_24-31_*_4) 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
- 3