day of month and day of week in crontab

Vote 0 Votes

發現 crontab 裡面的 day of month 及 day of week, 若同時指定的話, 是 OR 條件
查了一下, 真的是這樣, 之前一直以為是 AND

The time and date fields are:
field allowed values
----- --------------
minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sun, or use names)

截錄 man crontab
Commands are exe-cuted by cron(8) when the minute, hour, and month of year fields match the current time,
and at least one of the two day fields (day of month, or day of week) match the current time

若要達到 AND, 就要在 Command 中判斷了
例: 每個月1-3日, 且必須是週一到五早上8點執行
0 8 * 1-3 * root [ `date +\%w` -ge 1 -a `date +\%w` -le 5 ] && commands
% 在 crontab 是特殊字元, 要 escape

About this Entry

This page contains a single entry by Pank published on November 27, 2018 9:21 AM.

Shadowsocks server was the previous entry in this blog.

GCam (Pixel Camera) for Nokia 8.1 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Monthly Archives