为什么cron在启动后每分钟都会开始工作?

时间:2014-02-12 21:12:28

标签: unix cron

我安排一份工作在下午1点运行,但之后每分钟运行一次,为什么?

运行时输出:

$ crontab -l
* 13 * * * /bin/date >> /home/user/cron_work.log
$ tail -f /home/user/cron-work.log
Sun Feb 12 13:00:01 GMT+8 2012
Sun Feb 12 13:01:01 GMT+8 2012
Sun Feb 12 13:02:01 GMT+8 2012
Sun Feb 12 13:03:01 GMT+8 2012
Sun Feb 12 13:04:01 GMT+8 2012

请注意,第一个输出是好的,但不是其余的。谢谢。

1 个答案:

答案 0 :(得分:2)

因为你将它设置为每小时运行

* 13 * * * /bin/date >> /home/user/cron_work.log
^  ^ ^ ^ ^
|  | | | \- Run every day of the week
|  | | \--- Run every month
|  | \----- Run every day of the month
|  \------- Run only when the hour is 13 (1PM)
\---------- Run every minute

13:00匹配此模式,但13:01,13:02也是如此,依此类推,包括13:59。 14:00不匹配。

试试这个:

0 13 * * * /bin/date >> /home/user/cron_work.log
^  ^ ^ ^ ^
|  | | | \- Run every day of the week
|  | | \--- Run every month
|  | \----- Run every day of the month
|  \------- Run only when the hour is 13 (1PM)
\---------- Run only when the minute is 0

此模式仅在每天13:00运行。