logrotate는 와일드카드를 어떻게 처리합니까?

logrotate는 와일드카드를 어떻게 처리합니까?

이와 같은 logrotate 구성 파일이 있는 경우

# matches multiple ones
/var/log/project/*.log {
   ...

   prerotate
      ...
   endscript

   ...
} 

그럼 여기서 glob은 어떻게 작동하나요? 이 패턴과 일치하는 로그 파일이 3개 있는 경우 사전 회전 스크립트가 3번 실행됩니까, 아니면 한 번만 실행됩니까? 아무런 단서도 찾지 못했어요logrotate (8)

답변1

그만한 가치가 있기 때문에 logrotate는 man 3 glob에서 사용할 수 있는 glob.h( 참조: ) 를 사용합니다 man 7 glob. 여러 면에서 bash 와일드카드(확장된 와일드카드 없음)와 유사하지만 완전히 동일하지는 않습니다. 특히 이는 다음을 지원한다는 것을 의미합니다.

?      match a single character
*      match any string, including the empty string
[...]  match any of the listed characters
[a-z]  match a range of characters
[!...] match any but the listed characters
[:xx:] match various character classes, like [:digit:], [:blank:], etc.

와일드카드는 경로의 각 구성 요소에 개별적으로 적용됩니다. 예를 들어 여러 호스트에서 로그를 수집하는 rsyslog 서버가 있는 경우 다음과 같이 logrotate 섹션을 사용할 수 있습니다.

/var/log/host/*/*/syslog {
    rotate 5
    ...
}

답변2

일치하는 각 파일에 대해 한 번씩, 세 번 실행됩니다. 매뉴얼 페이지에 힌트가 있습니다:

sharedscripts
       Normally,  prerotate  and postrotate scripts are run for each log which is rotated and the absolute path
       to the log file is passed as first argument to the script. That means a single script may be run  multi-
       ple  times  for  log  file  entries which match multiple files (such as the /var/log/news/* example). If
       sharedscripts is specified, the scripts are only run once, no matter how many logs match the  wildcarded
       pattern,  and  whole  pattern  is  passed  to them.  However, if none of the logs in the pattern require
       rotating, the scripts will not be run at all. If the scripts exit with error, the remaining actions will
       not  be  executed  for  any  logs.  This  option overrides the nosharedscripts option and implies create
       option.

하지만 물론, 어디를 봐야 할지 아는 경우에만 이 사실을 알 수 있습니다. (또한 실험적으로 검증해봤습니다 logrotate -v;))

관련 정보