pbyrne / cron-checker

Source code for the Cron Checker site.
http://cronchecker.net/
Other
116 stars 17 forks source link

Day of week gives misleading explanation #10

Closed XeroXer closed 10 years ago

XeroXer commented 10 years ago

A few examples of the explanation given for cron strings containing the day of week.

0 0 * * 0 - The command - will execute at 12:00am every day and Sundays. Is only executed every Sunday, not every day.

0 0 1 * 0 - The command - will execute at 12:00am the 1st of every month and Sundays. Is only executed the 1st of every month if the 1st is a Sunday.

0 0 * 1 0 - The command - will execute at 12:00am every day of January and Sundays. Is only executed every Sunday of January.

pbyrne commented 10 years ago

Oh, thanks for reporting this. Your explanation differs from my testing/recollection of how weekdays are handled in crons. I'll dig deeper and make sure things are as they should be.

pbyrne commented 10 years ago

Ah ha, I think I was misreading the docs before. Only if both day of week and day of month are specified are they additive. I'm treating all uses of day of week as additive, which is incorrect. I'll get a fix in place shortly.

Thanks again for pointing this out.


Just to be doubly sure, I checked (man 5 crontab) against both a BSD system (Mac OS X) and a Linux system (Ubuntu), in case there was some kind of difference between them. There isn't.

Mac OS X

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, are not *),
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.

Ubuntu

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 (i.e., 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.  One can,  however,  achieve
the  desired result by adding a test to the command (see the last example in
EXAMPLE CRON FILE below).
pbyrne commented 10 years ago

I've deployed #12 which corrects the handling of weekdays.

However, your second example, 0 0 1 * 0 - still indicates the 1st of every month and every Sunday. From my reading of the docs (see previous comment with excerpts from man 5 crontab), if both day of month and day of week execute, "If both fields are restricted (i.e., aren't *), the command will be run when either field matches the current time."

XeroXer commented 10 years ago

Nice that the two weekday problems are solved. The second one is my mistake, more how I thought they worked without reading the docs. But checked and did a few tests and that one is correct, my bad.

pbyrne commented 10 years ago

No sweat on that mistaken example. Thanks again for calling this out. I was even more wrong. :grinning: