Decoding a crontab command
This is my first question on stackoverflow :)
I need t开发者_如何学Co add the following cPanel's crontab for a site I just migrated to hostgator, however I am having trouble understanding it.
Here is cron command that was passed:
*/30 * * * * /usr/local/bin/php /data/web/vhosts/advisorcheck.com/cron/geocode_paid_members.php
0 9,15 * * * /usr/bin/wget http://www.advisorbackgroundcheck.com/--spider
I need help in decoding the above and adding it to the crontab!
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
/usr/local/bin/php /data/web/vhosts/advisorcheck.com/cron/geocode_paid_members.php
at minutes :00, :30, every hour.Runs
/usr/bin/wget http://www.advisorbackgroundcheck.com/--spider
at minute :00, on hours 9, 15, every day.
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 = 10;
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-events.pl '0 9,15 * * *'
The next 10 events for the cron line:
0 9,15 * * *
will be:
Event 01 will start at 15:00:00 on 2017-02-21
Event 02 will start at 09:00:00 on 2017-02-22
Event 03 will start at 15:00:00 on 2017-02-22
Event 04 will start at 09:00:00 on 2017-02-23
Event 05 will start at 15:00:00 on 2017-02-23
Event 06 will start at 09:00:00 on 2017-02-24
Event 07 will start at 15:00:00 on 2017-02-24
Event 08 will start at 09:00:00 on 2017-02-25
Event 09 will start at 15:00:00 on 2017-02-25
Event 10 will start at 09:00:00 on 2017-02-26
The most recent event started at 09:00:00 on 2017-02-21
The first command will be executed every 30 minutes, while the second one will be executed twice a day (at 900 and 1500).
Here's an explanation of crontab syntax: http://en.wikipedia.org/wiki/Cron#Examples
精彩评论