views:

20

answers:

1

Guys,

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 apache as an environment variable and use that in apache's config. Is this possible?

Many Thanks again guys!

A: 

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.

bsterne
Awesome matie, will give it a try and let you know. Cheers
pravin
Damn my servers don't have logrotate installed yet and my mate suggested it was because of the complex dependencies we didn't build it in the first place. I haven't looked at it closely, is there any alternative for logrotate with fewer dependencies - i doubt it though? Otherwise I might have to write something myself which I don't like because I'm essentially reinventing the wheel. Thanks!
pravin