大网数据广告活动
服务器运维问答

How to specify exceptions from wildcard settings in a logrotate configuration file?

· 52CE 我爱测

For my logfiles I have the problem of all but one (or a few) files use the same configuration, while the rest has another one. I tried to realize this by giving a general configuration for all files and then overwriting this conf…

问题原文

原帖链接 · MRA · CC BY-SA 3.0

For my logfiles I have the problem of all but one (or a few) files use the same configuration, while the rest has another one. I tried to realize this by giving a general configuration for all files and then overwriting this configuration for the few specific files later, e.g.:

/var/log/mylogs/*.log {
                   size 1000k
                   copytruncate
                   create 0644 root root
                   rotate 99
                   compress
                   missingok
}

/var/log/mylogs/thatonespecial.log {
                   size 1000k
                   copytruncate
                   create 0644 myuser mygroup
                   rotate 99
                   compress
                   missingok
}

However, this raises an error:

error: /var/log/mylogs/logrotate.conf:10 duplicate log entry for /var/log/mylogs/thatonespecial.log

How should I handle such a situation properly? I certainly don't want to list the large number of standard log files individually, so the use of the wildcard configuration seems reasonable to me. But how can I then specify an exception among the wildcarded files?

已采纳解答

原帖链接 · Hyppy · CC BY-SA 3.0

The most elegant answer is to put thatonespecial.log in a separate directory so it wouldn't be able to match the wildcard.

If that won't work, then you can use globs to narrow down your wildcard. It's messy, but if you absolutely can't move the file location then it's probably your only real option. Something like this:

/var/log/mylogs/[!t][!h]*.log

Would match any .log files with at least 2 characters in their name that don't start with "th".

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-02-05)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。