Home > Operation and Maintenance > Apache > Tomcat implements regular deletion of logs

Tomcat implements regular deletion of logs

王林
Release: 2020-09-30 17:25:01
forward
3164 people have browsed it

Tomcat implements regular deletion of logs

Specific method:

(Recommended tutorial: apache)

1. Create script

vim /root/project/tomcat_logs_task/auto-del-15-days-ago-log.sh

# /bin/bash
#定期删除tomcat 定期删除15天前的已分割日志
 
#日志路径
apache_tomcat_api_8079=/root/app/apache-tomcat-job36-api-8079/logs
apache_tomcat_api_8080=/root/app/apache-tomcat-job36-api-8080/logs
 
apache_tomcat_admin_8081=/root/app/apache-tomcat-job36-admin-8081/logs
apache_tomcat_admin_8082=/root/app/apache-tomcat-job36-admin-8082/logs
 
 
find $apache_tomcat_api_8079 -mtime +15 -name "localhost_access_log.*" -exec rm -rf {} \;
find $apache_tomcat_api_8079 -mtime +15 -name "localhost.*" -exec rm -rf {} \;
find $apache_tomcat_api_8079 -mtime +15 -name "manager.*" -exec rm -rf {} \;
find $apache_tomcat_api_8079 -mtime +15 -name "catalina.*" -exec rm -rf {} \;
find $apache_tomcat_api_8079 -mtime +15 -name "host-manager.*" -exec rm -rf {} \;
 
find $apache_tomcat_api_8080 -mtime +15 -name "localhost_access_log.*" -exec rm -rf {} \;
find $apache_tomcat_api_8080 -mtime +15 -name "localhost.*" -exec rm -rf {} \;
find $apache_tomcat_api_8080 -mtime +15 -name "manager.*" -exec rm -rf {} \;
find $apache_tomcat_api_8080 -mtime +15 -name "catalina.*" -exec rm -rf {} \;
find $apache_tomcat_api_8080 -mtime +15 -name "host-manager.*" -exec rm -rf {} \;
 
 
find $apache_tomcat_admin_8081 -mtime +15 -name "localhost_access_log.*" -exec rm -rf {} \;
find $apache_tomcat_admin_8081 -mtime +15 -name "localhost.*" -exec rm -rf {} \;
find $apache_tomcat_admin_8081 -mtime +15 -name "manager.*" -exec rm -rf {} \;
find $apache_tomcat_admin_8081 -mtime +15 -name "catalina.*" -exec rm -rf {} \;
find $apache_tomcat_admin_8081 -mtime +15 -name "host-manager.*" -exec rm -rf {} \;
 
find $apache_tomcat_admin_8082 -mtime +15 -name "localhost_access_log.*" -exec rm -rf {} \;
find $apache_tomcat_admin_8082 -mtime +15 -name "localhost.*" -exec rm -rf {} \;
find $apache_tomcat_admin_8082 -mtime +15 -name "manager.*" -exec rm -rf {} \;
find $apache_tomcat_admin_8082 -mtime +15 -name "catalina.*" -exec rm -rf {} \;
find $apache_tomcat_admin_8082 -mtime +15 -name "host-manager.*" -exec rm -rf {} \;
Copy after login

2. Make an execution plan

vim /root/project/tomcat_logs_task/auto-del-15-days-ago-log.cron
0 1 * * * . /etc/profile;/bin/sh /root/project/tomcat_logs_task/auto-del-15-days-ago-log.sh
Copy after login

3. Join the task

crontab -e
0 1 * * * . /etc/profile;/bin/sh /root/project/tomcat_logs_task/auto-del-15-days-ago-log.sh
Copy after login

The above is the detailed content of Tomcat implements regular deletion of logs. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template