what interval does this cron run?
What interval does this CRON run?
*/5 0 * * * /comman开发者_如何学编程d
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
You cron runs every 5 minutes between midnight and 01h00 - not included.
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
精彩评论