我正在试图弄清楚如何在每个星期天运行crontab作业。我认为以下应该可以工作,但我不确定我是否理解正确。以下内容正确吗?
5 8 * * 6
我正在试图弄清楚如何在每个星期天运行crontab作业。我认为以下应该可以工作,但我不确定我是否理解正确。以下内容正确吗?
5 8 * * 6
当前回答
下面是对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
所以根据这个,你的5 8 * * 0会在每周日8:05运行。
其他回答
在指定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
参考:https://github.com/ncb000gt/node-cron
以人类可读的方式使用crontab构建器的Cron作业表达式
要在周日执行一个cron,你可以使用以下任何一种:
5 8 * * 0
5 8 * * 7
5 8 * * Sun
其中5 8代表这一事件发生的时间:8:05。
一般来说,如果你想在周日执行某项操作,只要确保第5列包含0、7或Sun中的任何一个。你有6个,所以周六在播。
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
您总是可以使用crontab。Guru作为一个编辑器来检查你的cron表达。
crontab网站提供了实时结果显示:https://crontab.guru/#5_8_*_*_0
我想你会喜欢这个交互式网站,它经常帮助我构建复杂的Crontab指令:https://crontab.guru/