特定日期的 Cron 表达式

发布于 2024-09-17 23:47:47 字数 47 浏览 6 评论 0原文

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

I want a cron expression that represents 6th September 2010 6:00 am

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

安静被遗忘 2024-09-24 23:47:47

原始问题被标记为 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).

Original question was tagged cron so this first section applies to that. See below for an updated answer for the Quartz CronTrigger tool.


Most crontabs don't let you specify the year so you'll probably have to put that in the script itself (or a wrapper around the script/program).

You can do this with something like:

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

The option you're looking for to run at 6am on September 6 every year is:

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

For the Quartz CronTrigger format, you'd be looking at something like:

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).
花辞树 2024-09-24 23:47:47

对于一次性作业,'at' 命令比 cron 更适合。

at -f filename 06:00 09/06/2010

For one-shot jobs the 'at' command is better suited than cron.

at -f filename 06:00 09/06/2010
维持三分热 2024-09-24 23:47:47

它只能在 /etc/crontab 中,如下所示:

0 6 6 9 * root test `/bin/date +%Y` == 2010 && <your command>

It could be only in /etc/crontab by follows:

0 6 6 9 * root test `/bin/date +%Y` == 2010 && <your command>
情话已封尘 2024-09-24 23:47:47

这会对你有所帮助。

At 02:30:00am, on the 23rd day, in April, in 2024

https://www.freeformatter.com/cron-expression-generator-quartz。 html
输入图片此处描述

This will help you.

At 02:30:00am, on the 23rd day, in April, in 2024

https://www.freeformatter.com/cron-expression-generator-quartz.html
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文