美文网首页
日志删除脚本

日志删除脚本

作者: M_ENG | 来源:发表于2021-11-05 12:03 被阅读0次
#进入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

相关文章

网友评论

      本文标题:日志删除脚本

      本文链接:https://www.haomeiwen.com/subject/viygqktx.html