Search This Blog

Tuesday, 12 April 2011

Script for Deleting a Specific day older files

 

#Source Directory
SRC=/apps/temp
#Specify size of file system in percentage when the script work. Nothing will happen if the FS utilization is below this.
CUTOFF=15
#Specify the age of file to be moved (older than this)
OLD=14
TS=`date "+%Y_%m_%d_%H:%M:%S"`
#location of Logfile
LOG=/tmp/mvfile.$TS
X=`df $SRC |grep -v Used|awk '{print $4}'|cut -c1-2|grep -v ^$`

if [ -f  $LOG ]
        then
        rm  $LOG
fi

if [[ $X -gt $CUTOFF ]]
then
        echo "/usr/bin/find $SRC -mtime +$OLD -print >>/tmp/mvfiles.$TS"
        /usr/bin/find $SRC -mtime +$OLD -print >>$LOG
                for i in `cat $LOG`
                do
                rm $i
                done
                echo "Log file Available:  $LOG"
fi

No comments:

Post a Comment