清理tomcat日志
参数1为Tomcat的log目录
参数2为日志保存的天数
删除要保存的天数的之外的所有的log日志
path=$1
saveDays=$2
cd $path
array_ls=(`ls |grep .log`);
array=()
for (( i=1; i<=$saveDays; i++ ))
do
DATE1=`date -d "$i days ago" +%Y-%m-%d`
array[${i}]=$DATE1
done
for v in ${array_ls[@]};
do
flag="666"
for t in ${array[@]};
do
aa=`echo $v |sed "s/.*\.\([0-9]\{4\}\-[0-9]\{2\}\-[0-9]\{2\}\)\..*/\1/g"`
if [[ "$aa" =~ "$t" ]];then
flag="777";
fi
done
if [[ "a$flag" =~ "a666" ]];then
rm -rf $v
fi
done