Linux Crontab 星期几语法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18919151/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Crontab Day of the Week syntax
提问by Marty Wallace
In crontab does the Day of the Week field run from 0 - 6
or 1 -7
?
在 crontab 中,星期几字段从0 - 6
或 开始运行1 -7
?
I am seeing conflicting information on this. wikipedia states 0-6
and other sites I have seen are 1-7
.
我看到有关此的相互矛盾的信息。维基百科状态0-6
和我见过的其他网站是1-7
.
Also what would be the implication or either using 0
or 7
incorrectly? i.e. would the cron still run?
还有什么含义或使用0
或7
不正确?即 cron 还会运行吗?
采纳答案by fedorqui 'SO stop harming'
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.
0
并且7
都代表星期天,你可以用你想要的那个,所以写 0-6 或 1-7 的结果是一样的。
Also, as suggested by @Henrik, it is possible to replace numbers by shortened name of days, such as MON
, THU
, etc:
此外,通过@Henrik的建议,也可以按天数,如缩短名称来代替数字MON
,THU
等:
0 - Sun Sunday
1 - Mon Monday
2 - Tue Tuesday
3 - Wed Wednesday
4 - Thu Thursday
5 - Fri Friday
6 - Sat Saturday
7 - Sun Sunday
Graphically:
图形化:
┌────────── 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
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.
最后,如果你想逐天指定,你可以用逗号分隔几天,例如SUN,MON,THU
只在星期日执行命令,在星期四星期一执行命令。
You can read further details in Wikipedia's article about Cron.
您可以在维基百科关于 Cron 的文章中阅读更多详细信息。
回答by Cyril Bouthors
You can also use day names like Mon
for Monday, Tue
for Tuesday, etc. It's more human friendly.
您还可以使用Mon
星期一、Tue
星期二等日期名称。它更人性化。
回答by Henrik
:-) Sunday | 0 -> Sun
|
Monday | 1 -> Mon
Tuesday | 2 -> Tue
Wednesday | 3 -> Wed
Thursday | 4 -> Thu
Friday | 5 -> Fri
Saturday | 6 -> Sat
|
:-) Sunday | 7 -> Sun
As you can see above, and as said before, the numbers 0
and 7
are both assigned to Sunday. There are also the English abbreviated days of the week listed, which can also be used in the crontab.
正如您在上面看到的,如前所述,数字0
和7
都分配给星期日。还有列出的英文缩写的星期几,也可以在crontab中使用。
Examples of Number or Abbreviation Use
数字或缩写使用示例
15 09 * * 5,6,0 command
15 09 * * 5,6,7 command
15 09 * * 5-7 command
15 09 * * Fri,Sat,Sun command
The four examples do all the same and execute a command every Friday, Saturday, and Sunday at 9.15 o'clock.
四个示例都做同样的事情,每周五、周六和周日 9.15 点执行一条命令。
In Detail
详细
Having two numbers 0
and 7
for Sunday can be useful for writing weekday ranges starting with 0
or ending with 7
. So you can write ranges starting with Sunday or ending with it, like 0-2
or 5-7
for example (ranges must start with the lower number and must end with the higher). The abbreviations cannot be used to define a weekday range.
有两个数字0
和7
for Sunday 可用于编写以 开头0
或结尾的工作日范围7
。所以,你可以写的范围开始星期日或与它的结局,像0-2
或5-7
例如(范围必须先从较低的数字,必须与更高端的)。缩写不能用于定义工作日范围。