I have a cron script that runs a few times every day throughout the year. However, around Christmas it should work differently. So my script looks basically like this:

# m h  dom mon dow   command
26 16 * JAN-NOV MON-THU (echo 14 `date`) >> /var/log/cron.www-data 2>&1
26 16 1-18 DEC MON-THU (echo 6 `date`) >> /var/log/cron.www-data 2>&1

where I replaced the actual command with a simple echo for debugging / demonstration purposes. For the exceptional case, I added some jobs like

26 07 19-24 DEC ? (echo 1 `date` ) >> /var/log/cron.www-data 2>&1

that actually work fine.

The problem is, that the second line above (echo 6) just got run, today December 19 -- the log file shows

6 Tue Dec 19 16:00:01 CET 2017

I guess my question is simply: Why did this job run?

I'm running Linux 3.18.11-v7+ #781 SMP PREEMPT Tue Apr 21 18:07:59 BST 2015 armv7l GNU/Linux on a Raspberry Pi.


The reason can be found in crontab(5):

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.

(Emphasis added)

I believe you want your script to run at the specified time from 1-18 December, but only from Monday to Thursday. As you can see from the manual page, cron doesn't do this when you specify both day of the month and day of the week. Your command will execute on every day from 1-18 December and on any day from Monday to Thursday in December. December 19, 2017 is a Tuesday, hence the script running.

Note: the above applies to ISC cron, the default on Debian systems.

  • Thanks, sometimes it's easy to overlook such subtleties! – CompuChip Dec 19 '17 at 16:00
  • I just got bit by overlooking this, and found your answer when researching "why". Who in the heck decided that's the right way to interpret the qualifiers??? – RonJohn Oct 31 '18 at 5:03

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.