My post on moving tomcat and cocoon logs has begun attracting a surprising number of Google vistors each day, all of whom seem to be searching on some variation of “how to rotate the catalina.out”
I suspect most of the vistors leave bitterly disappointed, as that post doesn’t really deal with rotating the catalina.out file so much as just moving it to a larger file system.
The catalina.out itself is nothing more than the standard output from the Tomcat servlet container. The problem is that Tomcat can be very talkative, which means the file can grow very large very quickly. I have tomcat instances on my Blackboard servers that produce 40+ megabyte files in a day during periods of normal use. A spot of heavy use or an error can cause these files to skyrocket in size, up to 2.5 gigs in one memorable instance. Growth like that can shut down an entire file system in nothing flat, and has.
In order to prevent that from happening, I started rotating the logs daily, keeping only the present and previous day’s logs on the system. This can be done with a fairly simple script. I’d not even put it up save for the fact that I’m getting hits from people who obviously don’t have one of their own.
Here tis:
#!/bin/ksh
#catrotate will copy and timestamp the catalina.out file daily
#in order to prevent it from growing too large.
name=`/bin/uname -n | cut -d. -f1`
case “$name”
in
webh|webi|webl|webm|webn )
cp -f /< path to >/catalina.out /< path to >/catalina.out.yest
cat /dev/null > /< path to >/catalina.out;;
webj )
for i in portal biblio costar hr cps oasis
do
cp -f /var/log/tomcat/$i/catalina.out /var/log/tomcat/$i/catalina.out.yest
cat /dev/null > /var/log/tomcat/$i/catalina.out
done;;
esac
Explanatory Notes: I have Tomcat instances on a number of machines, but for reasons too involved to go into I don’t have the log files in the same location on all of them. The first part of the case statement deals with 4 machines that have catalina.out files in the same place. The second part deals with one machine that has multiple catalina.out files in differing locations. The “for” statement steps through each location, clearing out the previous day’s entries from the catalina.out file and copying them to the catalina.out.yest file.
You getting all this down, Moms?
