Cronjob 在预定时间之前运行,可能出现什么问题?

Cronjob 在预定时间之前运行,可能出现什么问题?

我有以下 crontab 计划在 19-23 天之间的星期六运行,但我不知道为什么它会在 20 日(星期五)运行。有什么猜测吗?

00 21 19-23 * 6 <command>

答案1

该 Cron 表达式翻译为:

At 21:00 on the 19, 20, 21, 22 and 23rd of every month and every Saturday.

因此它明确告诉 cron 在 20 号星期五运行。这是因为:

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).

这些信息来自这个方便的 Cron 工具: http://crontab.guru/

为了使您的工作在星期六的特定日子运行,您可以使用:

00 21 19-23 * * test $(date +%u) -eq 6 && command

该解决方案来自crontab 星期几与每月哪一天?

相关内容