logrotate configuration file syntax - multiple wildcard entries possible?

99,958

Solution 1

Yes, you can use multiple wild cards. You can test your file without performing the actual rotations by doing this:

logrotate -d -f /etc/logrotate.conf
  • -d = Turns on debug mode. In debug mode, no changes will be made to the logs or to the logrotate state file.

  • -f = Tells logrotate to force the rotation, even if it doesn’t think this is necessary. Sometimes this is useful after adding new entries to logrotate, or if old log files have been removed by hand, as the new files will be created, and logging will con- tinue correctly.`

Solution 2

I just wanted to clarify, because that's what I got here looking how to do,

Multiple log files are allowed to be specified for a single config, eg

/var/log/httpd/access.log
/var/log/httpd/error.log
/var/log/httpd/mysite/*.log
{
    rotate 5
    mail [email protected]
    size 100k
    sharedscripts
    postrotate
        /usr/bin/killall -HUP httpd
    endscript
}

Solution 3

From man page for logrotate:

Note that log file names may be enclosed in quotes (and that quotes are required if the name contains spaces). Normal shell quoting rules apply, with ', ", and \ characters supported.

Please remember to modify or remove quotation marks when going from single to multiple patterns:

This works:

/var/log/*.log /var/log/*.blog {

this works too:

/var/log/*.log
/var/log/*.blog {

This does not work:

'/var/log/*.log /var/log/*.blog' {

and neither this:

"/var/log/*.log /var/log/*.blog" {

Compare with the single pattern case.

This works:

'/var/log/*.log' {

and this works too:

"/var/log/*.log" {

Tested with logrotate 3.10.0

Share:
99,958

Related videos on Youtube

0xC0000022L
Author by

0xC0000022L

human father bibliophile geek & ~nerd misanthropic philanthropist skeptic code necromancer programmer reverse engineer (RCE) / software archaeologist / grayhat hacker moderator on reverseengineering system administrator FLOSS enthusiast Debian, FreeBSD and Ubuntu aficionado

Updated on September 17, 2022

Comments

  • 0xC0000022L
    0xC0000022L over 1 year

    Since the man page doesn't answer my question and I don't want to force a rotation cycle, I decided to ask the question here.

    The man page for logrotate gives the following example:

       "/var/log/httpd/access.log" /var/log/httpd/error.log {
           rotate 5
           mail [email protected]
           size 100k
           sharedscripts
           postrotate
               /usr/bin/killall -HUP httpd
           endscript
       }
    

    All examples with wildcards contain only a single entry. Now, what I'm interested in is whether this one is also allowed:

       /var/log/httpd/*.log /var/log/httpd/*/*.log {
           # ... same as above
       }
    

    Here's the reasoning: I have multiple vhosts and I split them up by the user that "owns" those vhosts. Since the log files are world-readable, I want to bind-mount a folder into the user home directory, but limit it to the log files that the user "owns", which is easiest achieved by separating the logs into folders (and bind-mounting requires that scheme anyway). So I'm looking for a solution to rotate both the log files under /var/log/httpd as well as all log files under subdirectories of that directory - without having to list each and every subdirectory by name.

    In general the man page gives no clue whether multiple entries are at all possible for wildcard rules or only for full paths. I'm using logrotate version 3.7.8-6 which comes with Debian "Squeeze", but I reckon this is not necessarily specific to a distro or program version.

  • Nathan Basanese
    Nathan Basanese almost 7 years
    // , Is there not a problem with the different paths occurring on multiple lines?
  • ThorSummoner
    ThorSummoner almost 7 years
    @NathanBasanese I don't understand your question fully, I think you can point the path lines at files anywhere on disk you like, they dont all have to be in the same directory prefix.
  • KajMagnus
    KajMagnus about 6 years
    Would be interesting to know if this works: "/var/space /log/*.log" "/var/log/*.blog"
  • ThorSummoner
    ThorSummoner over 5 years
    @NathanBasanese oh, I think I understand, having multiple log rotation targets on different lines appears to be a normal use, i copied that form from other logrotate.d scripts, for example /etc/logrotate.d/rsyslog