清空目录下的日志
174总是提示磁盘空间满,于是写个脚本,定时清空那些大问题(〉300M),脚本如下:
#!/sbin/sh
####################script begin############################
echo "######################`date`####################"
find_del()
{
LOGDIR=$1
cd $LOGDIR || { echo "$LOGDIR not exists.";exit 0 ;}
echo "list files need to clear..."
find . -name "*.log.*" -size +300000 -exec ls {} \;
for file in `find . -name "*.log.*" -size +300000` ; do
cat /dev/null > $file
#echo $file
done
echo "cleared!!"
echo "#####################################################"
}
HOMEDIR=/tnms/jrtu
cd $HOMEDIR || { echo "$HOMEDIR not exists.";exit 0 ;}
for dir in `ls -l | grep '^d' | awk '{ print $NF }' | grep 'jrtu\-[0-9]'` ; do ##取/tnms/jrtu目录下以 "jrtu-数字" 开头的目录名;
if [ -d $dir ] ; then
echo $dir
logdir="$dir/logs"
echo $logdir
find_del $logdir
cd $HOMEDIR || { echo "$HOMEDIR not exists.";exit 0 ;} #退回到HOME目录,
#因为find_del会改换到jrtu目录下,所以下次循环就得不到下个目录名了!
fi
done
注: ls -l | grep '^d' | awk '{ print $NF }' | grep 'jrtu\-[0-9]' 取/tnms/jrtu目录下以 "jrtu-数字" 开头的目录名;
补充:综合编程 , 其他综合 ,