加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 如何使用crontab 在月份的第一,第二,第三和第四个星期

发布时间:2020-12-13 18:06:01 所属栏目:Linux 来源:网络整理
导读:参见英文答案 Why is my crontab not working,and how can I troubleshoot it?5个 我有4台服务器,我希望每台服务器在周日执行重启. 服务器1 – 本月的第一个星期日(第一周) 服务器2 – 本月的第二个星期日(第2周) 服务器3 – 本月第三个星期日(第3周) 服务器
参见英文答案 > Why is my crontab not working,and how can I troubleshoot it?5个
我有4台服务器,我希望每台服务器在周日执行重启.

>服务器1 – 本月的第一个星期日(第一周)
>服务器2 – 本月的第二个星期日(第2周)
>服务器3 – 本月第三个星期日(第3周)
>服务器4 – 本月的第四个星期日(第4周)

我怎么能用Crontab做到这一点?
谢谢!
多坦.

解决方法

第一个星期天总是在1日到7日之间
10 1 1-7 * * test `date +%a` == "Sun" &&  doSomething

在1日和7日之间的星期日,将在1点10分运行doSomething.类似地,第二个星期日将介于8日和14日之间,第三个星期日介于15日和21日之间,第四个星期日介于22日和28日之间,因此在相关服务器上相应地调整日期.

请注意,测试是必需的,因为

Note: The day of a command’s execution can be specified by two fields — day of month,and day of week. If both fields are restricted (ie,aren’t *),the command will be run when either field matches the cur- rent time. For example,“30 4 1,15 * 5” would cause a command to be run at 4:30 am on the 1st and 15th of each month,plus every Friday.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读