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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM