【问题标题】:How to write a cronTab expression to run a script every second Monday in a month at specified time?如何编写 cronTab 表达式以在指定时间每月第二个星期一运行脚本?
【发布时间】:2021-05-07 11:07:32
【问题描述】:

我的实例计划在一个月内每 7 天运行一次。我有两个程序 P1 和 P2,其中 P1 每周一下午 4 点运行,P2 每周一晚上 00:10 运行。

我的实例 crontab 表达式(每 7 天打开一次):

0 0 * * MON

我对 P1 的 crontab 表达式是:(在每 7 天的 16:00 运行 P1)

30 16 * * MON

现在我正试图弄清楚如何编写 crontab 表达式以在每个第二个星期一运行。

有相同的建议吗?

这是我的结构的外观:

今天是 5 月 7 日:星期五

下一步:

Machine On time: 10th May 00:00 (Monday)
P1 On time: 10th May 16:30 hrs
P2 On time: NA

下一步:

Machine On time: 17th May 00:00 (Monday)
P1 On time: 17th May 16:30 hrs
P2 On time: 17th May 00:10 hrs

下一步:

Machine On time: 24th May 00:00 (Monday)
P1 On time: 24th May 16:30 hrs
P2 On time: NA

等等。

【问题讨论】:

    标签: cron


    【解决方案1】:

    你可以做这样的事情 - 0 0 12 ? * 1#2。此 cron 作业将在每月的第二个星期一中午运行。

    你可以做类似的事情。 或者,如果您想探索更多类型,这里有一些有用的资源,您可以从中找到答案 -

    https://crontab.cronhub.io/

    https://www.freeformatter.com/cron-expression-generator-quartz.html

    https://crontab.guru/

    【讨论】:

    • 为什么是 12 天?没有得到那部分。
    • 您的表情似乎是每月第二个星期一中午 12:00。我更感兴趣的是在每个第二个星期一运行它,而不仅仅是每月的第二个星期一。抱歉,如果我让您感到困惑,但我要查找的是第 2 个星期一,然后是第 4 个星期一,依此类推
    • 是的,你是对的。每月第二个星期一中午 12:00。我也收到了你的问题。如果我能够根据您的要求提出一些 cron 表达式,会通知您。
    猜你喜欢
    • 1970-01-01
    • 2011-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-04
    • 1970-01-01
    • 2013-05-28
    相关资源
    最近更新 更多