我正在试图弄清楚如何在每个星期天运行crontab作业。我认为以下应该可以工作,但我不确定我是否理解正确。以下内容正确吗?

5 8 * * 6

当前回答

如果您不关心它在一天中的什么时间运行,我真的很想使用@weekly关键字运行。它应该在每个星期天运行,而且绝对更有可读性。

@weekly some_script.sh

其他回答

我想你会喜欢这个交互式网站,它经常帮助我构建复杂的Crontab指令:https://crontab.guru/

如果您不关心它在一天中的什么时间运行,我真的很想使用@weekly关键字运行。它应该在每个星期天运行,而且绝对更有可读性。

@weekly some_script.sh

下面是对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运行。

以人类可读的方式使用crontab构建器的Cron作业表达式

@每周工作对我更好! 例如,添加crontab -e,它将在每个周日0:00 AM工作 @weekly /root/fd/databasebackup/week.sh >> ~/test.txt