Ale*_*vić 4 linux ubuntu scheduled-task cron ubuntu-16.04
在 Ubuntu 16 上,我试图在工作日的上午 8:00 触发 cron 作业,这是我迄今为止尝试过的
0 8 * * 1-5 /path/to/command
Run Code Online (Sandbox Code Playgroud)
和
0 8 * * MON-FRI /path/to/command
Run Code Online (Sandbox Code Playgroud)
不起作用
小智 12
这些语法适用于所有工作日 a 8:00 AM :
0 8 * * 1-5 /path/to/command >/dev/null 2>&10 8 * * 1,2,3,4,5 /path/to/command >/dev/null 2>&1正如你所说的@aleksandar-pavi? 这些链接的更多解释:
的使用>/dev/null 2>&1是可选的,目标是将所有输出重定向到 /dev/null。
肯定有其他问题,如果使用crontab -e 还必须指定用户
这里提醒一下 cron 语法
* * * * * *
| | | | | |
| | | | | +-- Year (range: 1900-3000)
| | | | +---- Day of the Week (range: 1-7, 1 standing for Monday)
| | | +------ Month of the Year (range: 1-12)
| | +-------- Day of the Month (range: 1-31)
| +---------- Hour (range: 0-23)
+------------ Minute (range: 0-59)
Run Code Online (Sandbox Code Playgroud)
最后测试发现了答案,所以1-5,或者MON-FRI不起作用,有效的是
0 8 * * 1,2,3,4,5 /path/to/command
Run Code Online (Sandbox Code Playgroud)