首页 > 代码库 > ubuntu 定时备份清理tomcat日志,并且删除七天之前的日志

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日志,并且删除七天之前的日志