0

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!

1 Answer 1

1

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.

2
  • Awesome matie, will give it a try and let you know. Cheers Sep 24, 2010 at 14:57
  • 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! Sep 25, 2010 at 9:09

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.