I have a question. We have a cron job that executed on the 15th of this month:
min hr day month day_of_week
35 13 15 6 6However, it executed again on June 22nd (which was the 6th day of the week). Would the day_of_week take precedence over day & month that was already set before?
1 Answer
While normally the job is executed when the time/date specification fields all match the current time and date, there is one exception: if both "day of month" and "day of week" are restricted (not "*"), then either the "day of month" field (3) or the "day of week" field (5) must match the current day
So it happens only in June, at 13:35. Additionally it needs to be EITHER the 15th of June, or the 6th day of the week. Both at once will work too.
Running man 5 crontab will give you some additional information, they recommend you use test to specify both a specific date and restrict the weekday :
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).
[...]
# Run on every second Saturday of the month
0 4 8-14 * * test $(date +\%u) -eq 6 && echo "2nd Saturday" 4