ubuntu 定时备份清理tomcat日志,并且删除七天之前的日志

Posted Binz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ubuntu 定时备份清理tomcat日志,并且删除七天之前的日志相关的知识,希望对你有一定的参考价值。

#!/bin/bash

#logs_paths
#logs_paths[0]="/usr/local/webserver/tomcat/logs"
#logs_paths[1]="/usr/local/webserver/task_tomcat_8102/logs"
#logs_paths[2]="/usr/local/webserver/console_tomcat_8101/logs"

#for logs_path in ${logs_paths[@]}
#do
#  echo ‘123131312‘

#       find $logs_path -mtime +7 -name "localhost_access_log.*.txt" -exec rm -rf {} \;
#       find $logs_path -mtime +7 -name "catalina.*.log" -exec rm -rf {} \;
#       find $logs_path -mtime +7 -name "manager.*.log" -exec rm -rf {} \;
#       find $logs_path -mtime +7 -name "host-manager.*.log" -exec rm -rf {} \;
#       find $logs_path -mtime +7 -name "fileservice.log.*" -exec rm -rf {} \;

#done


#logs_paths
#logs_paths[0]="/usr/local/webserver/tomcat/logs"
logs_paths[0]="/usr/local/webserver/task_tomcat_8102/logs"
#logs_paths[1]="/usr/local/webserver/console_tomcat_8101/logs"
for logs_path  in ${logs_paths[@]};
do

        find $logs_path -mtime +7 -name "localhost_access_log.*.txt" -exec rm -rf {} \;
        find $logs_path -mtime +7 -name "catalina.*.log" -exec rm -rf {} \;
        find $logs_path -mtime +7 -name "manager.*.log" -exec rm -rf {} \;
        find $logs_path -mtime +7 -name "host-manager.*.log" -exec rm -rf {} \;
        find $logs_path -mtime +7 -name "fileservice.log.*" -exec rm -rf {} \;
        find $logs_path -mtime +7 -name "localhost.*.log" -exec rm -rf {} \;

        cp   $logs_path/catalina.out  $logs_path/catalina.`date +%Y-%m-%d`.log
        cat /dev/null > $logs_path/catalina.out
    echo $logs_path
done

 

以上是关于ubuntu 定时备份清理tomcat日志,并且删除七天之前的日志的主要内容,如果未能解决你的问题,请参考以下文章

tomcat日志切割和日志定时清理

ubuntu定时清理文件,如ros日志

linux定时任务之清理tomcat catalina.out日志

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

Linux定时清理30天前的Tomcat日志脚本

nginx--基于crond定时服务+shell脚本实现nginx日志自动清理及备份