从logrotate

时间:2015-08-28 11:24:05

标签: glob logrotate

我的目标是创建一个logrotate配置,为每组日志文件指定不同的转数。第一组为10,第二组为14,其余为5。这就是我到目前为止所做的:

~/log/myLog1*.log{
   rotate 10
   ...
}

~/log/myLog2*.log {
   rotate 14
   ...
}

~/log/[!{myLog1,myLog2}]*.log {
   rotate 5
   ...
}

以下显示了我想要旋转的文件:

ls ~/log/[!{myLog1,myLog2}]*.log

但由于logrotate doesn't support extended globbing,第3种模式不起作用,我收到此错误消息

rotating pattern: ~/log/[! forced from command line (5 rotations)
empty log files are not rotated, old logs are removed
considering log ~/log/[!
  log ~/log/[! does not exist -- skipping

任何人都可以纠正我的最终模式以便它起作用吗?

1 个答案:

答案 0 :(得分:0)

您是否尝试过将prerotate与排除配合使用?以下示例未经测试。

~/log/*.log {
   rotate 5
   nosharedscripts
   prerotate
       bash -c "[[ ! $1 =~ myLog1.log ]] && [[ ! $1 =~ myLog2.log ]]"
   endscript
}
~/log/myLog1.log {
   rotate 10
}
~/log/myLog1.log {
   rotate 14
}

source