这个 cron 运行的时间间隔是多少?

发布于 2024-10-07 15:55:09 字数 73 浏览 2 评论 0原文

这个 CRON 运行的时间间隔是多少?

*/5 0 * * * /command

What interval does this CRON run?

*/5 0 * * * /command

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迷鸟归林 2024-10-14 15:55:09

下面将每 5 分钟运行一次脚本 /home/user/test.pl,从整点后 0 分钟开始,然后是过去 5 分钟,依此类推。

*/5 * * * *  /home/user/test.pl

#  .---------------- minute (0 - 59) 
#  |   .------------- hour (0 - 23)
#  |   |   .---------- day of month (1 - 31)
#  |   |   |   .------- month (1 - 12) OR jan,feb,mar,apr ... 
#  |   |   |   |  .----- day of week (0 - 6) (Sunday=0 or 7) 
#  |   |   |   |  |
#  *   *   *   *  *  command to be executed

来自:http://en.wikipedia.org/wiki/Cron

The following will run the script /home/user/test.pl every 5 minutes starting at 0 minutes past the hour then 5 minutes past and so on.

*/5 * * * *  /home/user/test.pl

#  .---------------- minute (0 - 59) 
#  |   .------------- hour (0 - 23)
#  |   |   .---------- day of month (1 - 31)
#  |   |   |   .------- month (1 - 12) OR jan,feb,mar,apr ... 
#  |   |   |   |  .----- day of week (0 - 6) (Sunday=0 or 7) 
#  |   |   |   |  |
#  *   *   *   *  *  command to be executed

From: http://en.wikipedia.org/wiki/Cron

最近可好 2024-10-14 15:55:09

您的 cron 在午夜到 01:00 之间每 5 分钟运行一次 - 不包括在内。

You cron runs every 5 minutes between midnight and 01h00 - not included.

吝吻 2024-10-14 15:55:09

http://cronwtf.github.com/ 有一个有用的网站,您可以在其中粘贴 cron 行并它会给你一个关于它将做什么的英文解释。粘贴您的行会产生以下结果:

在分钟运行 /command :00, :05, :10, :15, :20, :25, :30, :35, :40, :45,每天 0 点 :50、:55。

请注意,0 小时是中午 12 点至凌晨 1 点。

还有一个 perl 模块 Schedule::Cron::Events 可以做一些事情类似地,该模块在 Ubuntu 16.04 中可用。希望它可以通过其他发行版包管理器获得。

要在 ubuntu 上安装该模块:

$ sudo apt install libschedule-cron-events-perl

在脚本中使用此模块:

#!/usr/bin/perl

use strict;
use warnings;

use Schedule::Cron::Events;

my $cron_line = shift;

my $count = 20;

my $cron = new Schedule::Cron::Events($cron_line, Seconds => time() );
my ($sec, $min, $hour, $day, $month, $year);

print "The next $count events for the cron line:\n\n" . $cron_line . "\n\nwill be:\n\n";

for (1..$count) {
    # find the next execution time
    ($sec, $min, $hour, $day, $month, $year) = $cron->nextEvent;
    printf(
        "Event %02d will start at %02d:%02d:%02d on %d-%02d-%02d\n",
        $_,
        $hour,
        $min,
        $sec,
        ($year+1900),
        ($month+1),
        $day,
    );
}

$cron->resetCounter;
($sec, $min, $hour, $day, $month, $year) = $cron->previousEvent;
printf(
    "\nThe most recent event started at %02d:%02d:%02d on %d-%02d-%02d\n",
    $hour,
    $min,
    $sec,
    ($year+1900),
    ($month+1),
    $day
);

将产生以下输出:

./cron-event.pl '*/5 0 * * *'
The next 10 events for the cron line:

*/5 0 * * *

will be:

Event 01 will start at 00:00:00 on 2017-02-22
Event 02 will start at 00:05:00 on 2017-02-22
Event 03 will start at 00:10:00 on 2017-02-22
Event 04 will start at 00:15:00 on 2017-02-22
Event 05 will start at 00:20:00 on 2017-02-22
Event 06 will start at 00:25:00 on 2017-02-22
Event 07 will start at 00:30:00 on 2017-02-22
Event 08 will start at 00:35:00 on 2017-02-22
Event 09 will start at 00:40:00 on 2017-02-22
Event 10 will start at 00:45:00 on 2017-02-22
Event 11 will start at 00:50:00 on 2017-02-22
Event 12 will start at 00:55:00 on 2017-02-22
Event 13 will start at 00:00:00 on 2017-02-23
Event 14 will start at 00:05:00 on 2017-02-23
Event 15 will start at 00:10:00 on 2017-02-23
Event 16 will start at 00:15:00 on 2017-02-23
Event 17 will start at 00:20:00 on 2017-02-23
Event 18 will start at 00:25:00 on 2017-02-23
Event 19 will start at 00:30:00 on 2017-02-23
Event 20 will start at 00:35:00 on 2017-02-23

The most recent event started at 00:55:00 on 2017-02-21

There is a useful site at http://cronwtf.github.com/ where you can paste cron lines and it will give you an English explanation of what it will do. Pasting your lines yields the following results:

Runs /command at minutes :00, :05, :10, :15, :20, :25, :30, :35, :40, :45, :50, :55, on hour 0, every day.

Note, hour 0 is 12am-1am.

There is also a perl module Schedule::Cron::Events that does something similar, this module is available in Ubuntu 16.04. Hopefully it is available via other distros package managers.

To install the module on ubuntu:

$ sudo apt install libschedule-cron-events-perl

Using this module in a script:

#!/usr/bin/perl

use strict;
use warnings;

use Schedule::Cron::Events;

my $cron_line = shift;

my $count = 20;

my $cron = new Schedule::Cron::Events($cron_line, Seconds => time() );
my ($sec, $min, $hour, $day, $month, $year);

print "The next $count events for the cron line:\n\n" . $cron_line . "\n\nwill be:\n\n";

for (1..$count) {
    # find the next execution time
    ($sec, $min, $hour, $day, $month, $year) = $cron->nextEvent;
    printf(
        "Event %02d will start at %02d:%02d:%02d on %d-%02d-%02d\n",
        $_,
        $hour,
        $min,
        $sec,
        ($year+1900),
        ($month+1),
        $day,
    );
}

$cron->resetCounter;
($sec, $min, $hour, $day, $month, $year) = $cron->previousEvent;
printf(
    "\nThe most recent event started at %02d:%02d:%02d on %d-%02d-%02d\n",
    $hour,
    $min,
    $sec,
    ($year+1900),
    ($month+1),
    $day
);

will produce the following output:

./cron-event.pl '*/5 0 * * *'
The next 10 events for the cron line:

*/5 0 * * *

will be:

Event 01 will start at 00:00:00 on 2017-02-22
Event 02 will start at 00:05:00 on 2017-02-22
Event 03 will start at 00:10:00 on 2017-02-22
Event 04 will start at 00:15:00 on 2017-02-22
Event 05 will start at 00:20:00 on 2017-02-22
Event 06 will start at 00:25:00 on 2017-02-22
Event 07 will start at 00:30:00 on 2017-02-22
Event 08 will start at 00:35:00 on 2017-02-22
Event 09 will start at 00:40:00 on 2017-02-22
Event 10 will start at 00:45:00 on 2017-02-22
Event 11 will start at 00:50:00 on 2017-02-22
Event 12 will start at 00:55:00 on 2017-02-22
Event 13 will start at 00:00:00 on 2017-02-23
Event 14 will start at 00:05:00 on 2017-02-23
Event 15 will start at 00:10:00 on 2017-02-23
Event 16 will start at 00:15:00 on 2017-02-23
Event 17 will start at 00:20:00 on 2017-02-23
Event 18 will start at 00:25:00 on 2017-02-23
Event 19 will start at 00:30:00 on 2017-02-23
Event 20 will start at 00:35:00 on 2017-02-23

The most recent event started at 00:55:00 on 2017-02-21
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文