Chinaunix首页 | 论坛 | 博客
  • 博客访问: 18681494
  • 博文数量: 7460
  • 博客积分: 10434
  • 博客等级: 上将
  • 技术积分: 78178
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-02 22:54
文章分类

全部博文(7460)

文章存档

2011年(1)

2009年(669)

2008年(6790)

分类:

2008-05-03 10:58:59

#!/bin/sh
########################################################################
# Desc: thie script is used to monitor file size,and backup it.
# Author:
# Date: 2004-09-06
#########################################################################

#Function: process the backup action.

backup()
{
AVASIZE=`df  .|grep -v Filesystem|awk -F" " '{print $4}'`
AVASIZE=`expr $AVASIZE \* 1000`

#echo $1

for F in $1
do
MBASENAME=`basename $F`
MDIRNAME=`dirname $F`
CURFILESIZE=`ls -l $F|grep -v total|grep -v "log.[0-9]\{4\}"|awk -F' ' '{print $5}'`
#***** IF FILTING SOME NOT VALID FILE,YOU MUST NOT COMPARE BELOW ******
if [ "$CURFILESIZE" == "" ];then
   continue;
fi
echo $AVASIZE $CURFILESIZE $MBASENAME $MDIRNAME
if [ $CURFILESIZE -lt $AVASIZE ];then
  echo "--- `date +%Y-%m-%d' '%T`: FOUND SO BIGGER FILE,BEGIN BACKUP ---" >> monitor_file_size.log
  cp $F $F".`date +%Y_%m_%d_%H_%M_%S`"
  #rm -f $F
  >$F  
  echo " File $F BACKUP TO $F.`date +%Y_%m_%d_%H_%M_%S`, File Size: $CURFILESIZE" >> monitor_file_size.log

  echo "--- `date +%Y-%m-%d' '%T`: END OF BACKUP ---" >> monitor_file_size.log
  echo "" >> monitor_file_size.log
else
  echo "WARNING: The partition has not enough space !"
fi
done;
}

if [ $# -ne 2 ]; then
echo "Usage: `basename $0` MONITOR_PATH MONITORFILE_SIZE(Mbytes)"
exit 0
fi

MPATH=$1
MSIZE=`expr $2 \* 1024`


backup "`find $MPATH -type f -size +$MSIZE -print`"
阅读(1318) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~