
Crontable 매개변수는 'ands' 조건으로 작동하는 것 같습니다. 그래서 예는
0 9-5 * * 1-5
"분은 0이고 시는 9시에서 5시 사이이고 일은 월요일과 금요일 사이에 있음"이라는 조건이 충족되면 실행됩니다.
내가 원하는 것은 '또는' 기능이므로 "월요일부터 금요일까지 또는 매월 8일에 실행"이라고 말할 수 있습니다. 그런 것이 존재하나요?
두 개의 항목을 추가할 수 있다는 것을 알고 있지만 항목이 많으면 잊을 만한 것이 추가됩니다.
답변1
나는 말할 예정이었다: ,
(쉼표)를 사용하십시오. 에서 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일마다 그리고 월요일부터 금요일까지 매일 명령이 실행됩니다.
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"