解码 crontab 命令

发布于 2024-10-14 06:52:59 字数 399 浏览 4 评论 0原文

这是我在 stackoverflow 上的第一个问题:)

我需要为我刚刚迁移到 hostgator 的站点添加以下 cPanel 的 crontab,但是我无法理解它。

这是传递的 cron 命令:

*/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

我需要帮助解码上述内容并将其添加到 crontab!

This is my first question on stackoverflow :)

I need to 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ま柒月 2024-10-21 06:52:59

http://cronwtf.github.com/ 有一个有用的网站,您可以在其中粘贴 cron 行并它会给你一个关于它将做什么的英文解释。粘贴您的行会产生以下结果:

运行/usr/local/bin/php
/data/web/vhosts/advisorcheck.com/cron/geocode_paid_members.php
位于
分钟 :00, :30,每小时。

运行 /usr/bin/wget http://www.advisorbackgroundcheck.com/--spider
每天 9 点、15 点:00 分钟。

还有一个 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 = 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
);

将产生以下输出:

$ ./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

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
诺曦 2024-10-21 06:52:59

第一个命令将每 30 分钟执行一次,而第二个命令将每天执行两次(900 和 1500)。

以下是 crontab 语法的说明: http://en.wikipedia.org/wiki/Cron#Examples< /a>

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文