Tomcat log cutting

Zelda of link 2022-06-24 08:00:00 阅读数:891


As the business grows ,catalina.out More and more big , Operation and maintenance is very inconvenient

Record myself yes catalina.out A practice of cutting

1. Cut script

cd `dirname $0`
DATE=`date +%Y-%m-%d`
DATE30=`date -d '30 days ago' +%Y-%m-%d`
cd /server/tomcat/logs/
ls others >/dev/null 2>&1
if [ $? != 0 ];then
mkdir others
find . -type f -mtime +30 -exec rm -f {} \;
cp catalina.out catalina.out.${DATE}
echo "" > catalina.out

among /server/tomcat/logs/ Change the correspondence to your own tomcat Log file path

Put the script in tomcat  bin Under the table of contents

After editing the script You need to give the script permission chmod +x

2. Whether it can be used under test execution


If appear No such file or directory

use vim Open the sh file , Input :

:set ff

enter , Show fileformat=dos, Reset the file format :

:set ff=unix

Save and exit :


Re execution , That's all right.

3. Add this script to linux In its own timed tasks

55 23 * * * /home/tomcat/bin/

notes : This command means in 23 spot 55 Execute this script separately , For specific time rules, please refer to :

Here are some commands for querying scheduled tasks

crontab -e  Edit scheduled tasks
crontab -l  View scheduled tasks created by the current user
sudo service crond start Start timing task
sudo service crond restart Restart scheduled tasks
sudo service crond stop Stop the scheduled task
cat /var/log/cron View the scheduled task execution log

4. The format of the cut log file is shown in the figure

In the process of practice, we should pay attention to the corresponding self tomcat There are no other complicated places in the log path

Not much said , We're moving bricks

copyright:author[Zelda of link],Please bring the original link to reprint, thank you.