AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 702628
Accepted
elliotp
elliotp
Asked: 2015-07-01 07:51:18 +0800 CST2015-07-01 07:51:18 +0800 CST 2015-07-01 07:51:18 +0800 CST

Crontab 一周中的某些天发生冲突

  • 772

我已经在 centos 6 crontab 上设置了备份轮换,一个脚本应该在周一到周六运行,另一个在周日运行,而不是在每月 1 日。然而,每周(仅限周日)脚本每晚都在运行,而每日脚本则在周日运行。由 cron.log 确认

#Daily - Midnight, Mon-Sat, Not on the 1st of the Month
0 0 2-31 * 1-6 script_daily

#Weekly - Midnight, Sunday, Not on the 1st of the Month
0 0 2-31 * 0 script_weekly

我无法弄清楚我做错了什么?

编辑:我已经从 cron 日志中提取了相关行。28 日是星期天。

Jun 28 00:00:01 backup CROND[2000]: (root) CMD (script_daily)
Jun 28 00:00:01 backup CROND[2004]: (root) CMD (script_weekly)
Jun 29 00:00:01 backup CROND[9438]: (root) CMD (script_daily)
Jun 29 00:00:01 backup CROND[9443]: (root) CMD (script_weekly)
Jun 30 00:00:02 backup CROND[6893]: (root) CMD (script_daily)
Jun 30 00:00:02 backup CROND[6898]: (root) CMD (script_weekly)
linux
  • 1 1 个回答
  • 349 Views

1 个回答

  • Voted
  1. Best Answer
    hymie
    2015-07-01T10:52:37+08:002015-07-01T10:52:37+08:00

    手册页

    If you  spec-
    ify  both  a day in the month and a day of week, it will be interpreted
    as the Nth such day in the month.
    

    [...]

    To request the last Monday, etc.  in a month, ask for  the  "5th"  one.
    This  will  always  match the last Monday, etc., even if there are only
    four Mondays in the month:
    
    
         # run at 11 am on the first and last Mon, Tue, Wed of each month
         0 11 1,5 * mon-wed date
    
    When the fourth Monday in a month is the last, it  will  match  against
    both  the "4th" and the "5th" (it will only run once if both are speci-
    fied).
    

    简而言之...

    0 0 2-31 * 1-6 script_daily
    

    每个月的第二个到最后一个星期一/星期二/星期三/星期四/星期五/星期六

    0 0 2-31 * 0 script_weekly
    

    每个月的第二个到最后一个星期日

    在我的脑海中,我怀疑正确的答案是“教你的脚本在看到它们在本月 1 日运行时立即退出”,然后运行你的工作

    0 0 * * 1-6 script_daily
    0 0 * * 0 script_weekly
    
    • 0

相关问题

  • Linux 主机到主机迁移

  • 如何在 Linux 机器上找到有关硬件的详细信息?

  • 如何在 Linux 下监控每个进程的网络 I/O 使用情况?

  • 在 RHEL4 上修改 CUPS 中的现有打印机设置

  • 为本地网络中的名称解析添加自定义 dns 条目

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve