#进入log目录
cd /log
#生成delete_log脚步文件
vim delete_log.sh
#workdir=("/log" "/xxxx")#可填写多个路径
workdir=("/log")
#可填写多个路径
for wdir in ${workdir[@]}
do
echo filepath is $wdir
if [ $wdir = ${workdir[0]} ] ;then
fileStr=`find $wdir/**/ -type d`
echo files is $fileStr
else
fileStr=`find $wdir -type d`
echo filee is $fileStr
fi
for dir in $fileStr
do
echo file name is $dir
find $dir -name '*.log*' -and -mtime +180 -type f | xargs rm -rf
if [ $? -eq 0 ];then
echo $date delete $dir success!
else
echo $date delete $dir FAILD!
fi
done
done
chmod 700 ./delete_log.sh
crontab -e
# 每天10点半定时执行日志
30 10 * * * root /log/delete_log.sh >> /log/delete_log.log
网友评论