tomcat 日志切割
#!/bin/bash tomcatRoot=/data/server/tomcats keepDays=30 managerLog="/data/shell/logs/`date '+%F'`.log" logDate=`date -d "-1 day" +%F` deleteLogDate=`date -d "-$keepDays day" +%F` for tomcatDir in `ls $tomcatRoot` do logDir="$tomcatRoot/$tomcatDir/logs" echo "<==================================================================================>" >> $managerLog 2>&1 echo "`date '+%F %T'` - start copy [$logDate] - $logDir/catalina.out" >> $managerLog 2>&1 if [ -e "$logDir/catalina.out" ]; then cp "$logDir/catalina.out" "$logDir/catalina.$logDate.out" else echo "$logDir/catalina.out file is not found" >> $managerLog 2>&1 echo "<==================================================================================>" >> $managerLog 2>&1 echo "" >> $managerLog 2>&1 continue fi echo "`date '+%F %T'` - remove all log in $logDir/catalina.out" >> $managerLog 2>&1 echo '' > "$logDir/catalina.out" if [ -e "$logDir/catalina.$deleteLogDate.out" ]; then rm -vf "$logDir/catalina.$deleteLogDate.out" echo "`date '+%F %T'` - delete $logDir/catalina.$deleteLogDate.out successful" >> $managerLog 2>&1 else echo "`date '+%F %T'` - delete $logDir/catalina.$deleteLogDate.out is not found" >> $managerLog 2>&1 fi echo "<==================================================================================>" >> $managerLog 2>&1 echo "" >> $managerLog 2>&1 done