clearFileNameArr=($(ls ${logPath}|awk -F "." ''NF==3{print $0}''))
# clear file name is not blank
if [ -n "${clearFileNameArr}" ];then
echo "|">>${scriptLog}
for((i=0;i<${#clearFileNameArr[@]};i ))
do
if [ ${i} -eq 0 ];then
echo "clear file------------------start--------------------------->">>${scriptLog}
fi
# cd this directory
cd ${logPath}
if [ -f "${logPath}/${clearFileNameArr[$i]}" ];then
find . -type f -name ${clearFileNameArr[$i]} |xargs rm -f
fi
if [ $? -eq 0 ];then
echo "${clearFileNameArr[$i]}">>${scriptLog}
fi
done
echo "clear file------------------------- end -------------------->">>${scriptLog}
echo "|">>${scriptLog}
else
echo "☆☆☆☆☆☆ Not files 1 day ago ☆☆☆☆☆☆">>${scriptLog}
fi
afterClearoldboyUsed=$(/bin/df ${oldboyName}|tail -1|awk ''{print $5}''|awk -F "%" ''{print $1}'')
echo "clear ${logPath} logs ${1} ago days logs successfully!">>${scriptLog}
fi
}
如果你把握不好该脚本带来的误删除的风险,请慎用.
#when today log save ,check hard disk used >80%,so clear today logs
clearTodayLog()
{
oldboyUsedTmp=$(/bin/df ${oldboyName}|tail -1|awk ''{print $5}''|awk -F "%" ''{print $1}'')
echo "clear today log start ...">>${scriptLog}
#todayFileArr=($(ls ${logPath}))
todayFileArr=($(find ${logPath} -type f|awk -F "/" ''{print $NF}'' ))
echo "start save current logs tail 300 ..">>${scriptLog}
echo "|">>${scriptLog}
echo "dealing currnet logs name*********start*************>>>>">>${scriptLog}
for((i=0;i<${#todayFileArr[@]};i ))
do
cd ${logPath}