文章转载自:https://blog.51cto.com/loong576/2091460
Tomcat的catalina.out日志分割有多种方式,如logrotate、cronolog等,本文采用最简单的shell方式。由于catalina.out日志会不断增长,故部署此脚本每天零点对日志文件进行割接,每天生成一个日志文件,便于查看。
# more /root/script/catalina_out.sh
#!/bin/sh
#该脚本用于catalina.out日志割接
y=`date "+%Y"`
m=`date "+%m"`
d=`date "+%d" -d "-1day"`
#for tomcat
log_file1=/home/tomcat/apache-tomcat-7.0.62/logs
#for csr
log_file2=/home/tomcat/apache-tomcat_csr/logs
cd $log_file1
cp catalina.out catalina.out.$y$m$d
echo > catalina.out
cd $log_file2
cp catalina.out catalina.out.$y$m$d
echo > catalina.out
exit
# crontab -l
0 0 * * * /root/script/catalina_out.sh 1>/dev/null 2>&1