10

I have below crontab scheduled for Saturday that falls between days 19-23, I' m not sure why it ran on 20th (Friday). Any guesses?

00 21 19-23 * 6 <command>
2
  • 1
    You might find some inspiration in /etc/cron.d/mdadm used on Ubuntu and Debian. This is how it runs the first Sunday of each month: 57 0 * * 0 root if [ -x /usr/share/mdadm/checkarray ] && [ $(date +\%d) -le 7 ]; then /usr/share/mdadm/checkarray --cron --all --idle --quiet; fi
    – kasperd
    Nov 23, 2015 at 20:00
  • thanks kasperd, 0 18 * * 6 [date +\%d -le 07] && <task> is working well for me, where it is required to run on first Saturday of every month.
    – simer
    Nov 30, 2015 at 14:01

1 Answer 1

16

That Cron expression translates to:

At 21:00 on the 19, 20, 21, 22 and 23rd of every month and every Saturday.

So it explicitly told cron to run on Friday the 20th. This is because of:

When the schedule specifies both date and weekday, they're combined with a logical OR,
i.e. the job will run if current_minute == scheduled_minute 
&& current_hour == scheduled_hour && current_month == scheduled_month && 
(current_day == scheduled_date OR current_weekday == scheduled_weekday).

This information is from this handy Cron tool: http://crontab.guru/

To make your job to run on given days when it is Saturday you could use:

00 21 19-23 * * test $(date +%u) -eq 6 && command

This solution is from crontab day of week vs. day of month?

1
  • 6
    Beware that % has a special meaning in cronjobs – it separates the command's stdin.
    – user1686
    Nov 23, 2015 at 13:21

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.