请问这个命令 0 11 4 * mon-wed /etc/init.d/smb restart 是每周一到周三的 11 点和每月的 4 号的 11 点重启 smb 吗?还是 每周一到周三 每逢 4 号 的 11 点重启? 谢谢,另外请问如何设置特定一天的定时任务?(不需要循环
1
446ENzu91KZ73A33 2021-05-14 17:09:18 +08:00
你好像需要这个 https://crontab.guru/#0_3_*_*_*
|
2
programV2 OP |
4
thunderw 2021-05-14 17:19:59 +08:00
man 5 crontab 可知,时间字段的含义如下
The time and date fields are: field allowed values ----- -------------- minute 0-59 hour 0-23 day of month 1-31 month 1-12 (or names, see below) day of week 0-7 (0 or 7 is Sunday, or use names) Note: The day of a command's execution can be specified in the follow‐ ing two fields — 'day of month', and 'day of week'. If both fields are restricted (i.e., do not contain the "*" character), the command will be run when either field matches the current 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. 如手册所言,星期和日期两个都指定的话,他们是或的关系,是并集。你举的例子表示周一到周三到或 4 号。 但是手册又说了,按名字不能指定范围啊 mon-wed 应该是不行的啊…… 我认为要写 1-3 Names can also be used for the 'month' and 'day of week' fields. Use the first three letters of the particular day or month (case does not matter). Ranges or lists of names are not allowed. |
6
446ENzu91KZ73A33 2021-05-14 17:23:43 +08:00
@programV2 0 17 14 5 * 这样能满足吗?每年的 5 月 14 号 17 点执行
|
8
Beebird 2021-05-14 17:28:53 +08:00
这样就是标准化的了:0 11 4 * 1-3
感觉为了方便阅读,可以写成两个任务啊: 0 11 * * 1-3 0 11 4 * * 一次性的任务用 at 比较合适 |