#!/bin/sh
tomcat_dir=$1 ##tomcat安装目录
mkdir -p /var/log/tomcat
file_size=`du ${tomcat_dir}/logs/catalina.out | awk '{print $1}'`
if [ $file_size -ge 102400 ]
then
if [ ! -d $tomcat_dir ]
then
echo `date +%Y-%m-%d-%H:%M:%S`":文件切割目录不存在" >> /var/log/tomcat/tomcat_cut.log
fi
cp ${tomcat_dir}/logs/catalina.out ${tomcat_dir}/logs/tomcat-log-`date +%Y-%m-%d-%H%M%S`.log #保存日志文件
echo `date +%Y-%m-%d-%H:%M:%S`"${tomcat_dir}:文件切割" >> /var/log/tomcat/tomcat_cut.log #记录切割日志
echo "" > ${tomcat_dir}/logs/catalina.out #清空tomcat的log/catalina.out文件内容
fi
##删除三天以前日志
find $tomcat_dir/logs -type f -mtime +3 -name "*.log" -o -type f -mtime +3 -name "*.txt" |xargs rm -f
crontab -l
#tomcat日志切割
01 00 * * * /bin/bash /home/scripts/t_cut.sh /home/deploy/tomcat8_8080 >/dev/null 2>&1