cronjob 在错误的日期执行

cronjob executed on wrong day

我想要一个脚本在每个季度的第一个星期六执行。 因此,我设置了一个 crontab 行,内容如下

24  9    1-7   1,4,7,10   6   /absolute/path/to/script

此脚本已于昨天执行,在 9:24(确定),星期六(确定),但在 10 月(确定)16 日(NOK)。

有什么我错过或误解的提示吗? 非常感谢。

脚本 运行 在指定月份的前 7 天 每个星期六的每一天。

原因在this crontab guru page (and crontab(5)'s man page) 中有很好的解释。相关片段是:

Note: The day of a command's execution can be specified in the following two fields --- 'day of month', and 'day of week'. If both fields are restricted (i.e., do not contain the "*" character), 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.

您可以通过检查说明以及您的脚本何时 运行 下一个(“下一个”)here.

来检查是否确实发生了这种情况

第一个星期六的脚本运行实现你想要的方法在其他questions/answers中有描述。例如,参见 Run a cron job on the first Monday of every month? or How to schedule to run first Sunday of every month。简而言之,将 6 替换为 * 并将您的命令与对 date.

的调用结合起来