这个cron运行的时间间隔是多少?
这个CRON运行的时间间隔是多少这个cron运行的时间间隔是多少?,cron,Cron,这个CRON运行的时间间隔是多少 */5 0 * * * /command 下面将每5分钟运行一次脚本/home/user/test.pl,从一小时后0分钟开始,然后再过5分钟,依此类推 */5 * * * * /home/user/test.pl # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) #
*/5 0 * * * /command
下面将每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
From:以下内容将每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
From:您的cron在午夜到凌晨1点之间每5分钟运行一次-不包括在内。您的cron在午夜到凌晨1点之间每5分钟运行一次-不包括在内。有一个有用的站点,您可以在其中粘贴cron行,它会给您一个关于它将做什么的英文解释。粘贴行会产生以下结果: 在每天第0小时的分钟:00,:05,:10,:15,:20,:25,:30,:35,:40,:45,:50,:55运行
/command
注意,第0小时为上午12点至凌晨1点
还有一个perl模块做类似的事情,这个模块在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
有一个有用的网站,你可以在那里粘贴cron行,它会给你一个关于它将做什么的英语解释。粘贴行会产生以下结果:
在每天第0小时的分钟:00,:05,:10,:15,:20,:25,:30,:35,:40,:45,:50,:55运行/command
注意,第0小时为上午12点至凌晨1点
还有一个perl模块做类似的事情,这个模块在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