unix / linux中的cron表达式允许指定确切的开始和结束日期 [英] Does cron expression in unix/linux allow specifying exact start and end dates

查看:1029
本文介绍了unix / linux中的cron表达式允许指定确切的开始和结束日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要配置类似这样的东西。

I want to be able to configure something like this.


  1. 我想在每天上午7点运行作业'X' 2009年6月29日至2009年12月30日。考虑当前日期为4/4/2009。


推荐答案

您需要为该范围提供三个单独的 cron 作业运行相同的代码(在这种情况下 X ):

You need three separate cron jobs for that range, all running the same code (X in this case):


  • 和6月30日(0 7 29,30 6 * X)。

  • 11月(​​0 7 * 7-11 * X)。

  • c $ c>0 7 1-30 12 * X)。

  • one for the 29th and 30th of June ("0 7 29,30 6 * X").
  • one for every day in the months July through November ("0 7 * 7-11 * X").
  • one for all but the last day in December ("0 7 1-30 12 * X").

# Min   Hr   DayOfMonth   Month   DayOfWeek   Command
# ---   --   ----------   -----   ---------   -------
   0     7      29,30        6        *          X
   0     7          *     7-11        *          X
   0     7       1-30       12        *          X

然后确保您在2010年6月29日之前发表评论周围。您可以在12月31日添加最后的 cron 职位,以电子邮件通知您需要停用。

Then make sure you comment them out before June 29, 2010 comes around. You can add a final cron job on December 31 to email you that it needs to be disabled.

可以修改 X 以在年份不是2009年时立即退出。

Or you could modify X to exit immediately if the year isn't 2009.

if [[ "$(date +%Y)" != "2009" ]] ; then
    exit
fi

禁用作业。

这篇关于unix / linux中的cron表达式允许指定确切的开始和结束日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆