Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

If I have a logrotate config file like this,

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

   prerotate
      ...
   endscript

   ...
} 

So how does the glob work here? If I have 3 log file matches that pattern, would the prerotate script get executed for 3 times or only once? I didn't find any clue in logrotate (8)

share|improve this question

2 Answers 2

up vote 2 down vote accepted

It's executed three times, once for each matching file. There's a hint in the man page:

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.

But of course, you only find that once you know to look there. (Also, I experimentally verified with logrotate -v ;) )

share|improve this answer

For what it's worth, logrotate uses glob.h (see: man 3 glob), which is documented very well in man 7 glob. It is similar in many ways to bash globbing (without extended globbing), but it's not identical. In particular, that means it supports:

?      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.

Globbing is applied to each component of the path separately. As an example, if I have an rsyslog server collecting logs from multiple hosts, I can use a logrotate stanza like:

/var/log/host/*/*/syslog {
    rotate 5
    ...
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.