tomcat日志切割脚本shell

tomcat-rotate.sh

#!/bin/bash

log_path="/home/tomcat7-api/logs/"
expried_time=7

function delete_log() {
local currentDate=`date +%s`

for file in find $1 -name "*.log" -o -name "*.txt"
do
local name=$file
local modifyDate=$(stat -c %Z $file)

local logExistTime=$(($currentDate - $modifyDate))
logExistTime=$(($logExistTime/86400))

if [ $logExistTime -gt $expried_time ]; then
echo "File: " $name "Modify Date: " $modifyDate + "Exist Time: " $logExistTime + "Delete: yes"
rm -f $file
fi
done
}

delete_log /home/tomcat7-api/logs/
delete_log /home/tomcat7-mobile/logs/
delete_log /home/tomcat7-pay/logs/
delete_log /home/tomcat7-web/logs/

上一篇:使用Git和远程代码库


下一篇:nginx学习笔记(四)-----日志切割脚本及定时任务