shell脚本删除log日志

删除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
原文地址:https://www.cnblogs.com/bjx2020/p/8086124.html