Linux: November 2018 Archives

發現 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 Archive

This page is an archive of entries in the Linux category from November 2018.

Linux: July 2018 is the previous archive.

Linux: May 2019 is the next archive.

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

Linux: Monthly Archives

Monthly Archives