Distributions
› Ubuntu
› Fedora
› CentOS
中文资源站
› 网易开源镜像站
bluemartin
V2EX  ›  Linux

cron 表达式中,有办法表达每月最后两天吗?

  •  
  •   bluemartin · Jun 28, 2021 · 6685 views
    This topic created in 1956 days ago, the information mentioned may be changed or developed.

    我知道每月最后一天是用 L 表示,例如:* * * L * ? 但每月最后两天,有没有办法用 cron 表达呢?搜索了一下没找到结果? 请大家指教。

    22 replies  •  2021-07-02 17:32:50 +08:00
    justfindu
    justfindu
    Jun 28, 2021
    1
    不能分两条吗
    justfindu
    justfindu
    Jun 28, 2021
    2
    L-1? 2L?
    Exple
    Exple
    Jun 28, 2021 via Android
    3
    sutra
    sutra
    Jun 28, 2021❤️1
    4
    Workaround: 设置成每天执行,然后在脚本上判断当前时间是不是这个月的最后两天。
    sutra
    sutra
    Jun 28, 2021
    5
    @Exple 还要考虑闰年吧。
    jadec0der
    jadec0der
    Jun 28, 2021
    6
    倒数第二天 0 0 0 L-1 * ? *
    cherbim
    cherbim
    Jun 28, 2021❤️2
    7
    分成两条,
    倒数第一天:0 0 18 L * ?
    倒数第二天:0 0 18 L-1 * ?
    AoEiuV020
    AoEiuV020
    Jun 28, 2021❤️1
    8
    第一反应也是每天执行用脚本判断,还是别为难 crontab 比较好,
    z740713651
    z740713651
    Jun 28, 2021❤️11
    9
    0 0 0 L-2 * ? *

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

    这么好用的工具安利一下
    leavic
    leavic
    Jun 28, 2021
    10
    还不如每天执行一次,然脚本自己判断日期来做。
    clf
    clf
    Jun 28, 2021
    11
    0 0 0 L-2 * ? *
    xiangyuecn
    xiangyuecn
    Jun 28, 2021❤️2
    12
    这货就跟正则表达式一样,老是有刁民想一句代码搞定😏😏
    bluemartin
    bluemartin
    OP
    Jun 28, 2021
    13
    @xiangyuecn 哈哈,是的
    bluemartin
    bluemartin
    OP
    Jun 28, 2021
    14
    @z740713651 非常好用,感谢
    bluemartin
    bluemartin
    OP
    Jun 28, 2021
    15
    @cherbim 谢谢指点,就这么办了
    xinyang5302677
    xinyang5302677
    Jun 28, 2021
    16
    每天执行一次 判断今天是不是最后两天
    tankren
    tankren
    Jun 28, 2021
    17
    每天跑 脚本自己判断今天是哪一天不就好了
    FurN1
    FurN1
    Jun 28, 2021 via iPhone
    18
    @xiangyuecn 哈哈哈到位,sed 用一行正则解决不了的,统统 AWK
    neowong2005
    neowong2005
    Jun 29, 2021
    19
    @AoEiuV020 #8 同意
    mr2xd
    mr2xd
    Jul 2, 2021
    21
    @z740713651 #9 貌似挂了
    z740713651
    z740713651
    Jul 2, 2021
    22
    @mr2xd #21 关键词 cron expression generator 其实网上一搜一大把


    https://en.rakko.tools/tools/88/
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3972 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 123ms · UTC 05:35 · PVG 13:35 · LAX 21:35 · JFK 00:35
    ♥ Do have faith in what you're doing.