开发者

How to define apache's logrotation's file name using an external shell script

I have apache running on different servers, I would like to rsync log files back to a centralised server on a daily basis. I can use log rotate to create log file for a day and put it in a directory that gets rsync'd to the central server. However is there any way to set the log filename with a designation that could be read from an external file?

The documentation says I can do the following, CustomLog "|/usr/sbin/rotatelogs -f /var/log/httpd/log 86400" common

I have an external config file which has a designation field which I can parse from command line to get its value, is there any way I can add it when file name gets defined. I'm curious to know if this designation can be passed to apach开发者_如何学编程e as an environment variable and use that in apache's config. Is this possible?

Many Thanks again guys!


I think you can do this by configuring Apache and logrotate. Logrotate is configured by scripts in the /etc/logrotate.d/ directory. For example, my default apache logrotate config file is: /etc/logrotate.d/httpd

/var/log/httpd/*log {
    missingok
    notifempty
    sharedscripts
    postrotate
    /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
    endscript
}

Check the logrotate man pages for the postrotate command. During the postrotate phase you could rename the log file and place it somewhere to be picked up by rsync.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜