Crontab 每3个月运行一次,从七月开始。

huangapple go评论46阅读模式
英文:

Crontab run every 3 months starting from July

问题

当我尝试让我的 crontab 每隔3个月从七月开始运行作业时,我使用了这个表达式 15 11 11 7/3 *,然后我收到了以下错误信息:crontab: installing new crontab "/tmp/crontab.vM7zCi":3: bad month errors in crontab file, can't install. 我尝试在网上阅读如何做这个,这应该是正确的吗?

英文:

When i tried to make my crontab to run a job every 3 months starting from July i use this expression 15 11 11 7/3 *
I then get this error.
crontab: installing new crontab
"/tmp/crontab.vM7zCi":3: bad month
errors in crontab file, can't install.

Ive tried reading online how to do this and this should be right?

答案1

得分: 1

如果你使用 */3,你的任务将在每个是3的倍数的月份运行(第3、6、9和12个月)。

通常,你可以通过结合一个范围后跟 /3 来指定你想要的内容,例如 1-12/3 —— 但月份或星期几字段不允许使用范围。引用 Vixie cron 的 crontab(5) 手册页,这是最常见的实现:

也可以使用名称来表示“月份”和“星期几”字段。
使用特定日或月的前三个字母(大小写不敏感)。不允许使用名称的范围或列表。

但是数字列表是允许的。因为你只想指定4个月,所以列出它们即可:

15 11 11 1,4,7,10 * 你的命令在这里
英文:

If you used */3, your job would run in every month that's a multiple of 3 (months 3, 6, 9, and 12).

Normally you could specify what you want by combining a range followed by /3, e.g. 1-12/3 -- but ranges are not allowed for the month or day-of-week fields. Quoting the crontab(5) man page for Vixie cron, the most common implementation:

> Names can also be used for the "month" and "day of week" fields.
> Use the first three letters of the particular day or month (case
> doesn't matter). Ranges or lists of names are not allowed.

But numeric lists are allowed. Since there are only 4 months you want to specify, just list them all:

15 11 11 1,4,7,10 * your-command-here

huangapple
  • 本文由 发表于 2023年7月11日 06:19:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76657667.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定