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>
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityThat 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?
%
has a special meaning in cronjobs – it separates the command's stdin.
Nov 23, 2015 at 13:21
/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
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.