#! /bin/sh
while true;
do
i=`df -h | egrep ‘/mnt/yourpath‘| awk ‘{print $5}‘ | cut -d "%" -f1 -`
if [ "$i" -ge 90 ]
then
echo "disk nearly full"
cd /mnt/yourpath
for file1day in `ls -d */ | sort -n | cut -d "/" -f1 -`
do
done
#for filedel in `ls -d */ | sort -n | cut -d "/" -f1 -`
for filedel in `ls | sort -n -`
do
rm -f $filedel
ii=`df -h | egrep ‘/mnt/yourpath‘| awk ‘{print $5}‘ | cut -d "%" -f1 -`
if [ "$ii" -lt 90 ]
then
break
fi
done
else
echo "disk space normal"
fi
sleep 120
done
#! /bin/sh
while true;
do
i=`df -h | egrep '/mnt/yourpath'| awk '{print $5}' | cut -d "%" -f1 -`
if [ "$i" -ge 90 ]
then
echo "disk nearly full"
cd /mnt/yourpath
for file1day in `ls -d */ | sort -n | cut -d "/" -f1 -`
do
done
#for filedel in `ls -d */ | sort -n | cut -d "/" -f1 -`
for filedel in `ls | sort -n -`
do
rm -f $filedel
ii=`df -h | egrep '/mnt/yourpath'| awk '{print $5}' | cut -d "%" -f1 -`
if [ "$ii" -lt 90 ]
then
break
fi
done
else
echo "disk space normal"
fi
sleep 120
done
注:/mnt/yourpath为待检测设备挂载目录,录像文件或日志文件等等
1、#! /bin/sh 是指此脚本使用/bin/sh来解释执行;
2、shell脚本中几种控制语句的写法 :
while true;
do
...
done
while true;
do
...
done
for ... in ...
do
...
done
for ... in ...
do
...
done
if
then
fi
其他的关键字和系统命令字面意思即可理解
原文:http://blog.csdn.net/weitao1234/article/details/39605037