Cron表达式每N分钟运行一次 [英] Cron expression to run every N minutes

查看:13518
本文介绍了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:


  1. 分钟

  2. 小时

  3. 每月的日期

  4. 每月的

  5. 星期几

  6. 命令

  1. Minute
  2. Hour
  3. Day of Month
  4. Month
  5. Day of Week
  6. Command

因此,在您的示例中,分钟为0,而您的小时无效(<小时$code>时间必须在 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分钟运行一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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