【问题标题】:Crontab to run at two hours out of the day, but for one of those hours exclude certain days of the weekCrontab 在一天中的两个小时运行,但其中一个小时不包括一周中的某些天
【发布时间】:2019-10-22 09:40:35
【问题描述】:

我需要更改以下时间表,以便仅在第 2 个小时排除周二和周四。

0 2,20 * * *

我想在每天凌晨 2 点和晚上 8 点运行一项工作,但周二和周四不包括凌晨 2 点的工作。

【问题讨论】:

标签: cron


【解决方案1】:

最简单的答案是在您的 crontab 中设置两个单独的条目:

# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

 * 2,20 *  *  0,1,3,5,6 root /path/to/command.sh
 *  20  *  *  2,4       root /path/to/command.sh

确保 command.sh 不在 /etc/cron.* 文件夹中。

【讨论】:

  • 谢谢,我忘了我可以有多个条目。这解决了它。
【解决方案2】:

我认为你需要的只是

0 2,20 * * 1,3,4,6,7

最后的数字是星期几。 O 是星期天。

【讨论】:

  • 星期天不是零就是七;星期一到星期六总是 1-6。阅读 cron 文档:“第 0-7 天(0 或 7 是星期日,或使用名称)”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-04
  • 1970-01-01
  • 2015-12-17
  • 2018-02-07
  • 1970-01-01
  • 2021-10-15
  • 2021-12-16
相关资源
最近更新 更多