My crons are as following, the error in /var/log/syslog is the title of the post.
# week */2 12/1 * * 1-5 tills13 python3 /home/tills13/script.py --sync 1/2 12/1 * * 1-5 tills13 python3 /home/tills13/script.py --sync # weekends */2 9/1 * * 0,6 tills13 python3 /home/tills13/script.py --sync 1/2 9/1 * * 0,6 tills13 python3 /home/tills13/script.py --sync
I used this tool to generate/validate my crons. I’m running Ubuntu 15.04.
Basically, I’d like it to run every hour after noon on weekdays (the first two), and every hour after 9am on weekends (the second two).
Depending on your flavor of cron, it may not love the / notation.
Rather than trying to make it super-compact, just tell it what you want it to do in a more acceptable to most/all versions of cron fashion. Might have the advantage of being more obvious to more humans, too. It’s a simple system – you really shouldn’t need a “tool” to create a crontab beyond a text editor. Since noon happens after 9, you only need to provide a “special case” for 9, 10 and 11 on Sunday and Saturday.
# every day at 2 minutes past the hour from Noon to 11 PM 2 12-23 * * * tills13 python3 /home/tills13/script.py --sync # weekends at 2 past the hours of 9, 10 and 11 2 9-11 * * 0,6 tills13 python3 /home/tills13/script.py --sync
Should also work for weekend (Sunday is 0 and 7):
2 9-11 * * 6-7 tills13 python3 /home/tills13/script.py --sync
if you want every hour at 2 minutes past.
I haven’t bothered to decode the / notation fully, (don’t recall it from my cron days 30 years ago and the wikipedia article is not comprehensive WRT it) but if you actually want every 2 minutes, just list them – 2,4,6,8,10,12 (etc)
9-11 in the hour field is equivalent to 9,10,11 (for example) and can be written either way and work. If you’d prefer to run ON the hour, change 2 in the minutes field to 0.
Minute Hour Day-of-Month Month Day-of-Week Command is all there is to standard crontab notation, with ranges of
0-59, 0-23, 1-31, 1-12, and 0-6 (but 7 is commonly accepted as 0 here) – the time fields can have comma separated lists or dash-separated ranges, or the * means all – whitespace separates the fields.