#背景:项目日志文件过大导致磁盘空间不足
#!/bin/bash
if [ -d "/usr/local/logs" ];then
if [ -z $1 ];then
Month2=`date -d yesterday +%Y-%m`
FilenameWeek=`date -d yesterday +%Y-%m--%V`
else
Month2=`date -d "-$1 month" +%Y-%m`
FilenameWeek=`date -d "-$1 month" +%Y-%m--%V`
fi
#Month2=`date -d "-1 month" +%Y-%m`
#FilenameWeek=`date -d yesterday +%Y-%m--%V`
date +%F" "%T > /tmp/findziplog
ifconfig |grep inet |grep 10 |grep netmask | awk '{print $2}' >> /tmp/findziplog
df -Th >> /tmp/findziplog
else
exit
fi
if [ -d "/usr/local/logs" ];then
cd /usr/local/logs
for Dir in $(ls -d ./*/*/$Month2)
do
cd $Dir
echo "/logs/HC_logs/$Dir"
Filename=`echo $Dir | awk -F/ '{print $2"_"$3}'`
find ./ -name '*.log' -mtime +0 -exec zip -m9 ${Filename}_${FilenameWeek}.zip {} \;
#find ./ -name '*.log' -mmin +40 -exec zip -m9 ${Filename}_${FilenameWeek}.zip {} \;
echo "${Filename}_${FilenameWeek}.zip"
cd /usr/local/logs
done
fi
df -Th >> /tmp/findziplog
date +%F" "%T >> /tmp/findziplog
标签:-%,tmp,FilenameWeek,logs,+%,清理,date,磁盘 From: https://www.cnblogs.com/zeno94/p/16726166.html