此cron运行的时间间隔是多少?

问题描述:

此CRON运行的时间间隔是多少?此cron运行的时间间隔是多少?

*/5 0 * * * /command 
+0

HTTP:// WWW。 unixgeeks.org/security/newbie/unix/cron-1.html – Adnan 2010-12-14 10:39:02

您的cron运行午夜01h00之间,每5分钟 - 不包括在内。

+0

谢谢......从00:00到01:00每5分钟一次吧? – 2010-12-14 11:03:24

以下将运行脚本/home/user/test.pl,每5分钟开始一小时过去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

http://cronwtf.github.com/有一个有用的网站,你可以粘贴cron行,它会给你一个英文解释它会做什么。粘贴您的线条将得到以下结果:

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

请注意,小时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