Cron表达式每N分钟运行一次

编程入门 行业动态 更新时间:2024-10-28 10:21:27
本文介绍了Cron表达式每N分钟运行一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要构建一个cron表达式以在用户单击开始按钮后每10分钟运行一次工作。

I need to build a cron expression to run a job every 10 minutes after the user click on start button.

我正在尝试执行以下操作:

I'm trying to do something like:

0 42/10 * * * ? *

42/10就像用户单击以hh:42开始(例如:18h42) 。下一个时间表是:

And 42/10 is like the user click to start at hh:42 (example: 18h42). The next schedule is like:

1. Friday, March 20, 2015 6:42 PM 2. Friday, March 20, 2015 6:52 PM 3. Friday, March 20, 2015 7:42 PM 4. Friday, March 20, 2015 7:52 PM 5. Friday, March 20, 2015 8:42 PM

问题是第二次执行后,作业等待一个小时才能执行下一次执行。我该如何构建一个cron表达式,该表达式可以立即启动并在N分钟后仍运行?

The problem is after second execution, the job waits like a hour to perform the next execution. How can i build a cron expression that starts immediately and after still running after N minutes?

预先感谢。

推荐答案

我认为您的格式错误。字段的顺序为:

I think your format is wrong. The order of the fields is:

  • 分钟
  • 小时
  • 每月的日期
  • 每月的
  • 星期几
  • 命令
  • Minute
  • Hour
  • Day of Month
  • Month
  • Day of Week
  • Command
  • 因此,在您的示例中,分钟为0,而您的小时无效(时间必须在 0-23 范围内)。我猜cron会忽略不正确的 Hour ,而是每小时每小时分钟0 运行。

    So in your example, the Minute is 0, and your Hour is invalid (Hour must be in the range 0-23). I'm guessing cron is ignoring the incorrect Hour, and running on Minute 0 of every hour.

    但是,如果您确实想每隔 N 分钟运行一次,则可以使用类似( N 小于60的格式):

    However, if you did want to run every N minutes, you could use a format like (where N is less than 60):

    0/N * * * * /bin/echo "Your Command Here"

    但是,请记住 / N 每隔都会重复命令当前小时内的N 分钟。因此,如果您的crontab中有 0/33 ,则您的命令将在以下位置运行:

    However, keep in mind that the /N repeats the command every N minutes within the current hour. So, if you have 0/33 in your crontab your command will run at:

    • 00:00
    • 00:33
    • 01:00
    • 01:33
    • 00:00
    • 00:33
    • 01:00
    • 01:33

    不在:

    • 00:00
    • 00:33
    • 01:06
    • 01:39
    • 00:00
    • 00:33
    • 01:06
    • 01:39

    更多推荐

    Cron表达式每N分钟运行一次

    本文发布于:2023-11-24 05:53:29,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1624162.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:表达式   Cron

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!