特定日期的 Cron 表达式

新手上路,请多包涵

我想要一个代表 2010 年 9 月 6 日上午 6:00 的 cron 表达式

原文由 NewBeee_Java 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 810
2 个回答

原始问题被标记为 cron 所以第一部分适用于此。有关 Quartz CronTrigger 工具的更新答案,请参见下文。


大多数 crontab 不允许您指定年份,因此您可能必须将其放在脚本本身(或脚本/程序周围的包装器)中。

你可以用这样的东西来做到这一点:

 # Only run in 2010.
if [[ $(date +%Y) != 2010 ]] ; then
    exit
fi

您要在 每年 9 月 6 日早上 6 点运行的选项是:

 0 6 6 9 * your_command_goes_here
│ │ │ │ │
│ │ │ │ └─ any day of the week.
│ │ │ └─── 9th month (September).
│ │ └───── 6th day of the month.
│ └─────── 6th hour of the day.
└───────── Start of the hour (minutes = 0).


对于 Quartz CronTrigger 格式,您会看到如下内容:

 0 0 6 6 9 ? 2010
│ │ │ │ │ │   │
│ │ │ │ │ │   └─ 2010 only.
│ │ │ │ │ └───── any day of the week.
│ │ │ │ └─────── 9th month (September).
│ │ │ └───────── 6th day of the month.
│ │ └─────────── 6th hour of the day.
│ └───────────── Start of the hour (minutes = 0).
└─────────────── Start of the minute (seconds = 0).

原文由 paxdiablo 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题