tomcat日志切割脚本
tomcat日志每俩小时切割的脚本如下(这是用定时任务来完成的,此方法无需重启tomcat):
time=$(date +%H) end_time=`expr $time - 2` a=$end_time BF_TIME=$(date +%Y%m%d)_$a:00-$time:00 cp /usr/local/tomcat8/logs/catalina.out /var/log/tomcat/oldlog/catalina.$BF_TIME.out echo " " > /usr/local/tomcat8/logs/catalina.out
#创建存放catalina.out日志的目录
mkdir -p /var/log/tomcat/oldlog/
#给脚本设置可执行权限
chmod +x /root/tom_log.sh
#设置定时任务,每两小时执行一次
crontab -e 0 */2 * * * sh /root/tom_log.sh
#最后的效果
ls /var/log/tomcat/oldlog/ catalina.20190102_15:00-17:00.out catalina.20190102_17:00-19:00.out