shell脚本删除log日志

送分小仙女□ 提交于 2019-11-29 00:23:22

删除log文件简单shell脚本

  经常会遇到日志把磁盘占满的情况,引起低级故障。我个人在实际工作中,尝试了如下的方法,比较简单,而且快捷有效。

#!/bin/bash
# /root/log_delete.sh
dir_log_1="/home/log/log1"
dir_log_2="/home/log/log2"
dir_log_3="/home/log/log3"

if  [ -d "${dir_log_1}" ]; then 
    find "${dir_log_1}"/* -name '*.txt' -mtime +14 -exec rm -rf {} \;
fi

if  [ -d "${dir_log_2}" ]; then 
    find "${dir_log_2}"/* -name '*.txt' -mtime +14 -exec rm -rf {} \;
fi

if  [ -d "${dir_log_3}" ]; then 
    find "${dir_log_3}"/* -name '*.txt' -mtime +14 -exec rm -rf {} \;
fi


chmod +x /root/log_delete.sh
sh /root/log_delete.sh

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!