How to run crontab job every week on Sunday
我想知道如何在周日每周运行一个crontab作业。我认为下面的内容应该有效,但我不确定我是否理解正确。以下内容正确吗?
1 | 5 8 * * 6 |
下面是对crontab格式的解释。
1 2 3 4 5 6 7 | # 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 |
因此,根据这一点,你的
要在周日执行cron,您可以使用以下任一选项:
1 2 3 | 5 8 * * 0 5 8 * * 7 5 8 * * Sun |
其中
一般来说,如果您想在周日执行某个操作,只需确保第5列包含
cronjobs的格式为:
1 2 3 4 5 6 7 | +---------------- 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 |
您可以始终使用crontab.guru作为编辑器来检查cron表达式。
下面是crontab文件的格式。
分钟小时月周用户shell脚本路径
因此,每个星期日午夜运行(星期日通常为0,在某些罕见情况下为7):
1 | 0 0 * * 0 root /path_to_command |
当指定cron值时,需要确保值在范围内。例如,一些cron使用0-7范围表示星期天,其中0和7都表示星期天。我们不(请看下面)。
1 2 3 4 5 6 | Seconds: 0-59 Minutes: 0-59 Hours: 0-23 Day of Month: 1-31 Months: 0-11 Day of Week: 0-6 |
参考:https://github.com/ncb000gt/node-cron
10×××太阳
1 2 3 4 5 | 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. |
1 2 3 4 5 6 7 8 9 10 11 12 | * * * * 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) |
@每周工作对我来说更好!
example,add the fellowing crontab -e ,it will work in every sunday 0:00 AM
@weekly /root/fd/databasebackup/week.sh >> ~/test.txt