centos定時刪除log文件


#!bin/bash
#獲取年
time=$(date "+%Y")

#查找並刪除7天前的文件
find /opt/applog/travelsky -type f -mtime +7 -exec rm -f {} \;
find /xcx/hislogs/logs -type f -mtime +7 -exec rm -f {} \;

#查找並刪除7天前的文件
find /usr/local/proxy-web/logs -type f -mtime +7 -exec rm -f {} \;

查找並刪除7天前的文件
find /var/www/html/wxsdairpro/log/ticket  -mtime +7 -exec rm -f {} \;
查找並刪除空目錄
find /var/www/html/wxsdairpro/log/ticket/$time -exec rmdir -p {} \;
find /var/www/html/wxsdairpro/log/ticket/$time  -mtime +7 -exec rm -f {} \;

find /var/www/html/wxsdairpro/log/order  -mtime +7 -exec rm -f {} \;
find /var/www/html/wxsdairpro/log/order/$time   -exec rmdir -p {} \;
find /var/www/html/wxsdairpro/log/order/$time  -mtime +7 -exec rm -f {} \;

find /var/www/html/wxsdairpro/log/mohe -mtime +7 -exec rm -f {} \;
find /var/www/html/wxsdairpro/log/mohe/$time   -exec rmdir -p {} \;
find /var/www/html/wxsdairpro/log/mohe/$time -mtime +7 -exec rm -f {} \;

find /var/www/html/wxsdairpro/log/checkinsure -mtime +7 -exec rm -f {} \;
find /var/www/html/wxsdairpro/log/checkinsure/$time   -exec rmdir -p {} \;
find /var/www/html/wxsdairpro/log/checkinsure/$time -mtime +7 -exec rm -f {} \;

find /var/www/html/wxsdairpro/log/checkin -mtime +7 -exec rm -f {} \;
find /var/www/html/wxsdairpro/log/checkin/$time   -exec rmdir -p {} \;
find /var/www/html/wxsdairpro/log/checkin/$time -mtime +7 -exec rm -f {} \;

 

文件命名為:del_log.sh

 

重新編輯:/etc/crontab

將文件:del_log.sh,以定時任務形式寫入到 /etc/crontab 中

 


免責聲明!

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



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