Linux 如何在星期日每周运行 crontab 作业
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16717930/
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
How to run crontab job every week on Sunday
提问by dev_fight
I'm trying to figure out how to run a crontab job every week on Sunday. I think the following should work, but I'm not sure if I understand correctly. Is the following correct?
我试图弄清楚如何在每周日运行 crontab 作业。我认为以下应该有效,但我不确定我是否理解正确。以下是否正确?
5 8 * * 6
采纳答案by Bjoern Rennhak
Here is an explanation of the crontab format.
这里是对 crontab 格式的解释。
# 1. Entry: Minute when the process will be started [0-60]
# 2. Entry: Hour when the process will be started [0-23]
# 3. Entry: Day of the month when the process will be started [1-28/29/30/31]
# 4. Entry: Month of the year when the process will be started [1-12]
# 5. Entry: Weekday when the process will be started [0-6] [0 is Sunday]
#
# all x min = */x
So according to this your 5 8 * * 0
would run 8:05 every Sunday.
因此,根据此您5 8 * * 0
将在每个星期日的 8:05 运行。
回答by xShirase
Following is the format of the crontab file.
以下是 crontab 文件的格式。
{minute} {hour} {day-of-month} {month} {day-of-week} {user} {path-to-shell-script}
{minute} {hour} {day-of-month} {month} {day-of-week} {user} {path-to-shell-script}
So, to run each sunday at midnight (Sunday is 0 usually, 7 in some rare cases) :
因此,要在每个星期日的午夜运行(星期日通常为 0,在极少数情况下为 7):
0 0 * * 0 root /path_to_command
回答by fedorqui 'SO stop harming'
To have a cron executed on Sunday you can use either of these:
要在周日执行 cron,您可以使用以下任一方法:
5 8 * * 0
5 8 * * 7
5 8 * * Sun
Where 5 8
stands for the time of the day when this will happen: 8:05.
哪里5 8
代表发生这种情况的一天中的时间:8:05。
In general, if you want to execute something on Sunday, just make sure the 5th column contains either of 0
, 7
or Sun
. You had 6
, so it was running on Saturday.
一般来说,如果您想在星期天执行某事,只需确保第 5 列包含0
,7
或Sun
。你有6
,所以它在星期六运行。
The format for cronjobs is:
cronjobs 的格式是:
+---------------- minute (0 - 59)
| +------------- hour (0 - 23)
| | +---------- day of month (1 - 31)
| | | +------- month (1 - 12)
| | | | +---- day of week (0 - 6) (Sunday=0 or 7)
| | | | |
* * * * * command to be executed
You can always use crontab.guruas a editor to check your cron expressions.
您始终可以使用crontab.guru作为编辑器来检查您的 cron 表达式。
回答by Mendon Ashwini
When specifying your cron values you'll need to make sure that your values fall within the ranges. For instance, some cron's use a 0-7 range for the day of week where both 0 and 7 represent Sunday. We do not(check below).
在指定您的 cron 值时,您需要确保您的值在范围内。例如,某些 cron 使用 0-7 范围表示星期几,其中 0 和 7 都代表星期日。我们不(检查下面)。
Seconds: 0-59
Minutes: 0-59
Hours: 0-23
Day of Month: 1-31
Months: 0-11
Day of Week: 0-6
reference: https://github.com/ncb000gt/node-cron
回答by Bachan Joseph
10 * * * Sun
10 * * * 太阳
Position 1 for minutes, allowed values are 1-60
position 2 for hours, allowed values are 1-24
position 3 for day of month ,allowed values are 1-31
position 4 for month ,allowed values are 1-12
position 5 for day of week ,allowed values are 1-7 or and the day starts at Monday.
回答by u5844373
@weekly work better for me!example,add the fellowing crontab -e ,it will work in every sunday 0:00 AM
@weekly /root/fd/databasebackup/week.sh >> ~/test.txt
@weekly 更适合我!example,add the fellowing crontab -e ,it will work in every sunday 0:00 AM
@weekly /root/fd/databasebackup/week.sh >> ~/test.txt
回答by Siddharth Bhandari
* * * * 0
you can use above cron job to run on every week on sunday, but in addition on what time you want to run this job for that you can follow below concept :
* * * * * Command_to_execute
- ? ? ? -
| | | | |
| | | | +?? Day of week (0?6) (Sunday=0) or Sun, Mon, Tue,...
| | | +???- Month (1?12) or Jan, Feb,...
| | +????-? Day of month (1?31)
| +??????? Hour (0?23)
+????????- Minute (0?59)
回答by Vytautas
Cron job expression in a human-readable way crontab builder
以人类可读的方式crontab 构建器的Cron 作业表达式
回答by jasper
I think you would like this interactive website, which often helps me build complex Crontab directives: https://crontab.guru/
我想你会喜欢这个交互式网站,它经常帮助我构建复杂的 Crontab 指令:https: //crontab.guru/