1

The crontab(5) manual says:

Commands are executed by cron(8) when the minute, hour, and month of year fields match the current time, and when at least one of the two day fields (day of month, or day of week) match the current time (see ``Note'' below). cron(8) examines cron entries once every minute. The time and date fields are:

field          allowed values
-----          --------------
minute         0-59
hour           0-23
day of month   1-31
month          1-12 (or names, see below)
day of week    0-7 (0 or 7 is Sun, or use names)

It also says:

A field may be an asterisk (*), which always stands for ``first-last''.

And in examples there is:

 @weekly        Run once a week, "0 0 * * 0".

From asterisk description, "0 0 * * 0" is the same as "0 0 1-31 1-12 0". My question is why doesn't every day match this expression? Documentation says

when the minute, hour, and month of year fields match the current time, and when at least one of the two day fields (day of month, or day of week) match the current time

So why aren't both 2019.12.25 00:00 and 2019.12.26 00:00 valid moments for this expression?

Both of them satisfy the "minute, hour, and month of year fields match the current time", as month is 1-12 and minute and hour are 0.

And also both of them will satisfy the "at least one of the two day fields (day of month, or day of week) match the current time" - as the day of the month is 1-31 and one satisfaction is enough.

Where am I wrong?

  • The note says: Note: 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 (ie, aren't *), the command will be run when either field matches the current time. For example, "30 4 1,15 * 5" would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday. Doesn't this mean that "0 0 1,15 * 1-7" will include every day of month, meaning that writing * and writing 1-7 lead to different expressions? – Aleksandre Tskhovrebovi Aug 29 at 20:44
3

As drewbenn commented, you missed ‘see “Note” below’.

Note: The day of a command's execution can be specified in the following two fields — 'day of month', and 'day of week'. If both fields are restricted (i.e., do not contain the "*" character), the command will be run when either field matches the current time.

0 0 * * 0 has * for the day of month, so the either-field rule does not apply. If one of the day fields is * and the other is not *, the command runs only when the non-* field matches. This is an exception to the rule that * is equivalent to a numeric range.

The mistake in the manual is that the sentence

A field may contain an asterisk (*), which always stands for “first-last”.

fails to mention this exception.

0

The last field specifies only running on Sunday. The day and month fields are wide-open in order to guarantee that every Sunday will be picked up. This is working as advertised.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.