大网数据广告活动
服务器运维问答

Why did my cron job run this month?

· 52CE 我爱测

Today is November 1st 2016 or in (unambiguous) numerals, 2016-11-01. I have a user cron job set up like this: # m h dom mon dow command 33 3 1 */2 * /home/user/... It is supposed to run every other month on the first of the month…

问题原文

原帖链接 · comfreak · CC BY-SA 3.0

Today is November 1st 2016 or in (unambiguous) numerals, 2016-11-01.

I have a user cron job set up like this:

# m h  dom mon dow   command
33  3   1  */2  *    /home/user/...

It is supposed to run every other month on the first of the month at 3:33am, no matter what day of week that is, but for some reason it was run today, even though 11 is not divisible by 2.

Can someone explain me this? Is my assumption of divisibility by 2 wrong?

EDIT: I forgot to mention, I am running cron version "3.0pl1-127+deb8u1" on a Debian 8.6 "Jessie" machine.

已采纳解答

原帖链接 · Sven · CC BY-SA 3.0

The / is not an arithmetic expression, instead it describes "step values" over the allowed range of values. So, since months always start with 1 instead of 0, /2 would mean "take every other value", resulting in (1, 3, 5, 7, 9, 11).

This is also decribed in the manual page, although this is not terrible clear and easy to understand:

Step values can be used in conjunction with ranges. Following a range with "<number>" specifies skips of the number’s value through the range. For example, "0-23/2" can be used in the hours field to specify command execution every other hour (the alternative in the V7 standard is "0,2,4,6,8,10,12,14,16,18,20,22"). Steps are also permitted after an asterisk, so if you want to say "every two hours", just use "*/2".

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-11-01)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。