#!/bin/bash log_path=/xxxxx/yyyyy/logs bak_log=/aaaaa/bbbbb bak_name=log_$(date +%Y-%m-%d) day=30 d=`date +%Y-%m-%d` [ ! -d $bak_log ] && mkdir $bak_log cd ${log_path} find . -type f -mtime +7 \( -name "*.log" -o -name "*.txt" \) -exec mv {} $bak_log \ ; cp catalina.out $bak_log/catalina.out.$d.log echo >catalina.out sleep 3 cd $bak_log tar -czf $bak_name.tar.gz *.{log,txt} rm -f *.{log,txt} delname=log_$(date -d "$day day ago" +%Y-%m-%d).tar.gz rm -f $delname
转载于:https://blog.51cto.com/2475296/1846907