0

According to Artur Meinild's answer here, the "day of month" and "day of week" fields of a crontab are mutually exclusive. However, according to man 5 crontab (for cronie, if it matters):

Commands are executed by cron(8) when the 'minute', 'hour', and 'month of the year' fields match the current time, and at least one of the two 'day' fields ('day of month', or 'day of week') match the current time

So, is the following line an error, or instructions to run /bin/true on every Wednesday plus the second day of each month? Is cronie's man page documenting standard behavior, or an application-specific quirk?

* * 2 * 3    /bin/true
  • 2
    The man page linked from that answer is pretty clear that they are not mutually exclusive: "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. 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." – Michael Homer Aug 1 '20 at 4:56
  • 1
    As it says in the passage you quoted: “Commands are executed by cron(8) when (…) at least one of the two 'day' fields ('day of month', or 'day of week') match the current time”. I don't see what else there is to add. It's not an error, it has a well-defined, and pretty much useless behavior. – Gilles 'SO- stop being evil' Aug 1 '20 at 9:16
  • @Gilles'SO-stopbeingevil', but is it standard well-defined useless behavior, or well-defined useless behavior specific to one flavor of cron? – Mark Aug 2 '20 at 22:47
2

The POSIX specification for crontab, being worded in the language of a standard—aiming to minimize ambiguity—has probably the clearest explanation (emphasis added, paragraph split for clarity):

The specification of days can be made by two fields (day of the month and day of the week).

If month, day of month, and day of week are all <asterisk> characters, every day shall be matched.

If either the month or day of month is specified as an element or list, but the day of week is an <asterisk>, the month and day of month fields shall specify the days that match.

If both month and day of month are specified as an <asterisk>, but day of week is an element or list, then only the specified days of the week match.

Finally, if either the month or day of month is specified as an element or list, and the day of week is also specified as an element or list, then any day matching either the month and day of month, or the day of week, shall be matched.

This confirms that:

  1. The task in your example is executed if the current day is either a Wednesday or the second day of the month.

  2. This is a documented standard behavior.

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.