嵌入式linux下自动定时检测硬盘空间并删除旧文件脚本

[plain] view plaincopyprint?

    #! /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/shwhile true;doi=`df -h | egrep '/mnt/yourpath'| awk '{print $5}' | cut -d "%" -f1 -`if [ "$i" -ge 90 ]thenecho "disk nearly full"cd /mnt/yourpath for file1day in `ls -d */ | sort -n | cut -d "/" -f1 -`dodone#for filedel in `ls -d */ | sort -n | cut -d "/" -f1 -`for filedel in `ls | sort -n -`dorm -f $filedelii=`df -h | egrep '/mnt/yourpath'| awk '{print $5}' | cut -d "%" -f1 -`if [ "$ii" -lt 90 ]thenbreakfidoneelseecho "disk space normal"fisleep 120done

注:/mnt/yourpath为待检测设备挂载目录,录像文件或日志文件等等

1、#! /bin/sh 是指此脚本使用/bin/sh来解释执行;

2、shell脚本中几种控制语句的写法 :

[plain] view plaincopyprint?

    while true; do … done
while true;do...done

[plain] view plaincopyprint?

    for … in … do … done
for ... in ...do...done

[plain] view plaincopyprint?

    if then fi
if thenfi

其他的关键字和系统命令字面意思即可理解

接受失败也等于给了自己从零开始的机会,

嵌入式linux下自动定时检测硬盘空间并删除旧文件脚本

相关文章:

你感兴趣的文章:

标签云: