[WEB4LIB] Re: log file rotation
Darryl Friesen
Darryl.Friesen at usask.ca
Thu Jan 10 15:41:45 EST 2002
> Or alternatively:
>
> #!/usr/bin/ksh
>
> today=`/usr/bin/date +"%Y%m%d"`
> # That will get the date automatically.
Those little "details" were left as an excercise for the user.
I guess since you one-up'd me I'd better try the same. :)
How about
#!/bin/sh
today=`/usr/bin/date +"%Y-%m-%d"`
cd /data/logs/www
for file in *_log ; do > /dev/null 2>&1
mv -f $file $file.$today
gzip $file.$today
done
/usr/local/apache/bin/apachectl graceful
This is pretty much what we do. It renames and compresses all "_log" files
(we use OpenSSL and a few other custom things that write files with names
like that). Just quick note to those that may attempt this. Restarting the
webserver is a must. Unix machines are fairly smart. If you simply move
the file, the OS knows that and will continue to log to that newly named
file. Stopping or restarting the web server will flush data to the file,
close it, then reopen a new one.
> I'm old enough that my scripts still find and "kill -HUP" the Apache
> proccess ID. Apache has just gotten so user friendly over the
> years. Who'da thunk it would ever have a "graceful" option? :->
I actually just changed my cron jobs this week to use the graceful option
(we replaced our Alpha with a Sun, so I had to tweak everything). I don't
know how long it's been there.
- Darryl
----------------------------------------------------------------------
Darryl Friesen, B.Sc., Programmer/Analyst Darryl.Friesen at usask.ca
Education & Research Technology Services, http://gollum.usask.ca/
Information Technology Services Division,
University of Saskatchewan
----------------------------------------------------------------------
"Go not to the Elves for counsel, for they will say both no and yes"
More information about the Web4lib
mailing list