【问题标题】:Cron expression for particular date特定日期的 Cron 表达式
【发布时间】:2011-04-09 14:09:17
【问题描述】:

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

【问题讨论】:

    标签: spring cron expression quartz-scheduler


    【解决方案1】:

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


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

    你可以这样做:

    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.
    +--------- Top 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.
    | +------------- Top of the hour (minutes = 0).
    +--------------- Top of the minute (seconds = 0).
    

    (详情来自here)。

    【讨论】:

    • 能否解释一下各个字段
    • 来自quartz-scheduler.org/docs/tutorials/crontrigger.html 我们还需要提到时分秒
    • @NewBie,CronTrigger 不是 cron。我从未见过允许指定秒数或年数的 cron。 Quartz 可能允许这样做,我不知道,因为我从未使用过它,但是,如果您的问题是关于 Quartz/CronTrigger 而不是真正的 cron,您应该重新标记它。
    • 第二个字段仍然缺少 pax
    • 您需要编辑您的答案第二个字段未正确标记。感谢@org。
    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      只能在 /etc/crontab 中如下:

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

      【讨论】:

        猜你喜欢
        • 2021-11-13
        • 1970-01-01
        • 2016-08-07
        • 2012-06-04
        • 1970-01-01
        • 2014-08-15
        • 2014-06-23
        相关资源
        最近更新 更多