0

I have found the following entry in our crontab, and wanted to make sure that I have interpreted it correctly:

0 */2 * * * [some command]

I am assuming that this means run the command twice a day on the hour. i.e. at 12:00 and 00:00.

Assuming this is the case, it leads me to also ask what happens if I choose a number that doesn't divide neatly, e.g.

 0 * * * */2 [some command]

I'm assuming this would mean run on the hour every hour, but only on 2 days of the week - but which days given that a week does not easily divide into 2?

paul frith
  • 101
  • 4

1 Answers1

2

You're close. The first example would run every two hours. The second would on days divisible by two. 0 is Sunday and 6 is Saturday so we would end up with some interesting behaviour as it should run Sunday, tuesday (2), Thursday (4), Saturday (6), and then Sunday again (0).

  • Thank you - so to clarify, `0 * */15 * *` would run every hour on the 15th and the 30 of every month - so in effect February would only have 1 day of the job running due to there being no 30th... –  Mar 08 '17 at 16:32
  • 1
    Yes, although for full clarity let's break this down: it will run on the 0 minute, every hour, on days divisible by 15 (15 & 30, once in Feb), every month, any day of the week. If you wanted it to run once on those days you'd want to define the hour as well. –  Mar 08 '17 at 16:38