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/
原文地址:https://www.cnblogs.com/immense/p/11405394.html
时间: 2024-10-28 07:45:12