# root_dir 为系统日志根目录,清除*.log 且非error开通的日志,应用压测时日志增长过快磁盘爆满。
#!/bin/bash
function getdir(){
for element in `ls $1`
do
dir_or_file=$1"/"$element
if [ -d $dir_or_file ]
then
getdir $dir_or_file
else
str=${dir_or_file##*.}
filename=${dir_or_file##*/}
s=${filename%.*}
result=$(echo $s | grep "error")
if [ "$str" = "log" ] && [ ! $result ];
then
true > $dir_or_file
echo $s
fi
fi
done
}
root_dir="/home/logs"
getdir $root_dir