此CRON的运行间隔是什么时间?
*/5 0 * * * /command
答案 0 :(得分:4)
以下将每隔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
答案 1 :(得分:1)
你的cron在午夜和01:00之间每隔5分钟运行一次 - 不包括在内。
答案 2 :(得分:0)
在http://cronwtf.github.com/有一个有用的网站,您可以在其中粘贴cron行,它会为您提供英语说明。粘贴线条会产生以下结果:
在分钟:00,:05,:10,:15,:20,:25,:30,:35,:40,:45,:50,:55,在小时0运行/command
,每一天。
注意,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