Answers:
我会说:用 ,
(逗号)。从 man 5 crontab
:
Lists are allowed.
A list is a set of numbers (or ranges) separated by commas.
Examples: "1,2,5,9","0-4,8-12".
但是你的情况稍微复杂一点,你可以利用这个功能:
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 (i.e., aren't *),
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.
所以在你的情况下,你可以写 0 9-5 8 * 1-5
。这将在每个月的8号和周一到周五的每一天执行命令。
另一种解决方案是使用a test
( man bash
,部分条件表达,和 man date
):
# Run on every second Saturday of the month:
0 4 8-14 * * test $(date +%u) -eq 6 && echo "2nd Saturday"