[Shell] Monitor filesystem usage & delete expire file

tolilong發表於2016-03-03
[root@oracle6 source]# crontab -l
5,15,25,35,45,55 * * * * /home/mon/source/mon_filesystem_full >> /home/mon/log/mon_filesystem_full.log

[root@oracle6 source]# 
[root@oracle6 source]# 
[root@oracle6 source]# more mon_filesystem_full 
#!/bin/bash
#monitor local filesystem is fully

LOG=/home/mon/data/filesystem_full.txt
FILE=/u01/oracle/product/11.2.0/dbhome_1/dbs
df -P > $LOG

cat $LOG | grep % | while
read LINE
do
  PCT=`echo $LINE | awk '{print $5}'`
  PCTD=`echo $PCT | tr "%" " "`
  if [ $PCTD -gt 64 ]; then
      #echo "$PCTD"
      ls -tr $FILE/arch*dbf | head -10 | while
      read NAME
      do
        #echo "$NAME"
         rm $NAME
      done
      
  fi
done

find $FILE -name "arch*dbf" -mtime +30 -type f -exec rm -rf {} \;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24237320/viewspace-2029576/,如需轉載,請註明出處,否則將追究法律責任。

相關文章