0

*/58 * * * * /usr/bin/php -f ....过去每 58 分钟跑步一次。但是我需要构建一个可以每 2 小时 11 分钟运行一次的 cron。有没有办法做到这一点?

4

2 回答 2

1

This:

*/58 * * * * /usr/bin/php -f ....

doesn't run every 58 minutes. Just as */5 in the minutes field runs at every minute after the hour that's a multiple of 5, */58 runs at every minute after the hour that's a multiple of 58. In other words, the job will run at 00:00, 00:58, 01:00, 01:58, 02:00, 02:58, etc.; the interval between two runs alternates between 58 minutes and 2 minutes.

There are probably tools other than cron that will do what you want. But if you want to use cron for this, you can have a job that runs every minutes:

 * * * * * your-wrapper-script /usr/bin/php -f ...

and implement your-wrapper-script so it executes its arguments only if the current time is a multiple of 131 minutes (2 hours, 11 minutes).

This Perl script should do the trick:

#!/usr/bin/perl

use strict;
use warnings;

my $now = time;
my $minutes = int($now/60);
if ($minutes % 131 == 0) {
    system @ARGV; # NOTE: No error detection
}
于 2012-07-29T04:00:40.513 回答
1

你可以使用at. 一旦在系统启动时调用at -f /path/script.sh "now + 131minutes"它,它将在 131 分钟的正常运行时间后启动 /path/script.sh。然后,在 /path/script.sh 中,插入另一个at. 见http://linux.die.net/man/1/at

于 2012-07-29T02:27:28.350 回答