Author: Loki
Date: 20-11-01 20:07
If the real reason you want to rotate logs is because you want to keep your /var size down, and you have a web stats package in your crontab, something like the script I use may be what you want.
I have the following shell script in my crontab; it runs daily, not long after Webalizer, which also runs daily. It renames the main Apache log, restarts Apache, sleeps for ten minutes, then copies the last 100 lines of the log back to the original logfile.
The 600 is probably much higher than necessary, but it doesn't really matter. Also, my webserver is fairly low-traffic and I don't often get 100 hits in between the time Webalizer and this script run, both in the middle of the night. :) You have to have some sleep time in there, though, so Apache has time to restart and recreate the logfile.
Webalizer also doesn't care if the logfile entries are out of order, as it reads their times from the entries themselves. It will also ignore duplicate records, which will often happen with this shell script (and in fact should happen; if you're not getting duplicate records when you run Webalizer - or whatever you use - increase the number in the tail line; you're losing hits in your stats.)
#!/bin/sh
mv /var/log/apache/main-access.log /var/log/apache/main-access.foo
kill -USR1 `cat /var/run/httpd.pid`
sleep 600
tail -n 100 /var/log/apache/main-access.foo >> /var/log/apache/main-access.log
rm /var/log/apache/main-access.foo
|
|