创建文件clear_tomcat_log.sh
#!/bin/bash logs_paths[0]="app_tomcat7_8080";
logs_paths[1]="app_tomcat7_8081";
logs_paths[2]="mgmt_tomcat7_8090"; for logs_path in ${logs_paths[@]}
do
find /usr/local/tomcat/$logs_path/logs -mtime +7 -name "localhost_access_log.*.txt" -exec rm -rf {} \;
find /usr/local/tomcat/$logs_path/logs -mtime +7 -name "catalina.*.log" -exec rm -rf {} \;
find /usr/local/tomcat/$logs_path/logs -mtime +7 -name "manager.*.log" -exec rm -rf {} \;
find /usr/local/tomcat/$logs_path/logs -mtime +7 -name "host-manager.*.log" -exec rm -rf {} \;
find /usr/local/tomcat/$logs_path/logs -mtime +7 -name "localhost.*.log" -exec rm -rf {} \;
find /usr/local/tomcat/$logs_path/logs -mtime +7 -name "carmall-manager.*.log" -exec rm -rf {} \;
echo “清理成功$logs_path”
#备份日志
cp $logs_path/catalina.out $logs_path/catalina.`date +%Y-%m-%d`.log
#清空日志
cat /dev/null > $logs_path/catalina.out
echo $logs_path
done
执行命令bash clear_tomcat_log.sh