til

Today I Learned: collection of notes, tips and tricks and stuff I learn from day to day working with computers and technology as an open source contributor and product manager

View project on GitHub

Scheduling with cron

Getting your head around the crontab syntax can be a little work.

I can recommend the following resources:

One thing I have observed that I had not given much thought earlier is, that it is not easy to schedule something to run bi-weekly, you can do something along the lines of:

0 0 1,15 * * /path/to/script.sh

This runs:

  • at: 00:00
  • on day-of-month: 1 and 15

Alternatively you could do:

0 0 * * 1 [ $(( $(date +\%V) \% 2 )) -eq 0 ] && /path/to/script.sh

This is untried it should run:

  • at: 00:00
  • Works well, but relies on ISO week numbers (reset yearly)
  • Pick odd (-eq 1) or even (-eq 0) to choose your starting week

I really need to try this out, since I do not know if crontab can be programmatically configured like that, which would be really powerful.

Resources and References