Crontab 星期几语法 [英] Crontab Day of the Week syntax

查看:25
本文介绍了Crontab 星期几语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 crontab 中,星期字段是从 0 - 6 还是 1 -7 开始运行?

In crontab does the Day of the Week field run from 0 - 6 or 1 -7?

我看到了关于此的相互矛盾的信息.维基百科声明 0-6 和我见过的其他网站是 1-7.

I am seeing conflicting information on this. wikipedia states 0-6 and other sites I have seen are 1-7.

还有什么含义或者错误地使用 07 ?即 cron 还会运行吗?

Also what would be the implication or either using 0 or 7 incorrectly? i.e. would the cron still run?

推荐答案

07 都代表星期天,你可以用你想要的,所以写0-6 或 1-7 具有相同的结果.

0 and 7 both stand for Sunday, you can use the one you want, so writing 0-6 or 1-7 has the same result.

此外,正如@Henrik 所建议的,可以通过缩短的日期名称来替换数字,例如 MONTHU 等:

Also, as suggested by @Henrik, it is possible to replace numbers by shortened name of days, such as MON, THU, etc:

0 - Sun      Sunday
1 - Mon      Monday
2 - Tue      Tuesday
3 - Wed      Wednesday
4 - Thu      Thursday
5 - Fri      Friday
6 - Sat      Saturday
7 - Sun      Sunday

图形上,* * * * * 要执行的命令代表:

<头>
分钟小时一个月的第几天星期几
(0-59)(0-23)(1-31)(1-12)(1-7)
*****要执行的命令

或者使用旧样式:

 ┌────────── minute (0 - 59)
 │ ┌──────── hour (0 - 23)
 │ │ ┌────── day of month (1 - 31)
 │ │ │ ┌──── month (1 - 12)
 │ │ │ │ ┌── day of week (0 - 6 => Sunday - Saturday, or
 │ │ │ │ │                1 - 7 => Monday - Sunday)
 ↓ ↓ ↓ ↓ ↓
 * * * * * command to be executed

最后,如果要逐日指定,可以用逗号分隔几天,例如SUN,MON,THU只会在星期日执行命令,星期一在星期四执行.

Finally, if you want to specify day by day, you can separate days with commas, for example SUN,MON,THU will exectute the command only on sundays, mondays on thursdays.

您可以在 维基百科关于 Cron 的文章 中阅读更多详细信息,并使用 crontab.guru.

You can read further details in Wikipedia's article about Cron and check a cron expression online with crontab.guru.

这篇关于Crontab 星期几语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆