采用shell脚本定时清理Tomcat日志

时间:2021-02-24 15:55:55

1 Shell脚本案例 删除超过30天的日志文件

#!/bin/bash
log_path=/mnt/software/apache-tomcat-9.0..M22/logs
d=`date +%Y-%m-%d`
d90=`date -d'30 day ago' +%Y-%m-%d`
#cd ${log_path} && cp catalina.out $log_path/cron/catalina.out.$d.log
#echo > catalina.out
rm -rf $log_path/catalina.out.${d90}*.log
rm -rf $log_path/localhost.${d90}*.log
rm -rf $log_path/student/talkilla-student*.${d90}*.log
rm -rf $log_path/wechat/talkilla-wechat*..${d90}*.log
rm -rf $log_path/teacher/talkilla-teacher*.${d90}*.log
rm -rf $log_path/consultant/talkilla-consultant*..${d90}*.log
rm -rf $log_path/admin/talkilla-admin*.${d90}*.log

2 配置定时执行,每天23点30分执行一次

crontab  -e
* * * root sh /mnt/software/shell/clear-tomcat-log.sh