#!/bin/bash cur_year=`date +%Y` #Current year follow by the server time, 2005 cur_month=`date +%b` #Current month follow by the server time, Dec month_01='01' #Numeric variable assign to month month_02='02' month_03='03' month_04='04' month_05='05' month_06='06' month_07='07' month_08='08' month_09='09' month_10='10' month_11='11' month_12='12' interval='3' #Rototion in month before a DN report will be removed for name in /home/cyzie/bash/hd1/DNReport/*/* do bname=$(basename $name) fname_year=${bname:11:4} fname_month=${bname:8:3} bal_year=`expr $cur_year - $fname_year` #Difference year between current year and file name year echo balance year is $bal_year dif_month=`expr 12 \* $bal_year` #Calculate the total diffence year echo dif month is $dif_month dif_month=`expr 12 \* $bal_year` #Calculate the total diffence year dif_month=`expr 12 \* $bal_year` #Calculate the total diffence year case $fname_month in #Convert character type to numeric type for file name month Jan) num_fmonth=$month_01;; Feb) num_fmonth=$month_02;; Mac) num_fmonth=$month_03;; Apr) num_fmonth=$month_04;; May) num_fmonth=$month_05;; Jun) num_fmonth=$month_06;; Jul) num_fmonth=$month_07;; Aug) num_fmonth=$month_08;; Sep) num_fmonth=$month_09;; Oct) num_fmonth=$month_10;; Nov) num_fmonth=$month_11;; Dec) num_fmonth=$month_12;; esac case $cur_month in #Convert character type to numeric type for current month Jan) num_cmonth=$month_01;; Feb) num_cmonth=$month_02;; Mac) num_cmonth=$month_03;; Apr) num_cmonth=$month_04;; May) num_cmonth=$month_05;; Jun) num_cmonth=$month_06;; Jul) num_cmonth=$month_07;; Aug) num_cmonth=$month_08;; Sep) num_cmonth=$month_09;; Oct) num_cmonth=$month_10;; Nov) num_cmonth=$month_11;; Dec) num_cmonth=$month_12;; esac if [ "$dif_month" -eq "0" ] #Comparation of the duration year then duration=`expr $num_cmonth - $num_fmonth` elif [ $dif_month -gt 0 ] then cur_duration=`expr $dif_month - $num_fmonth` duration=`expr $cur_duration + $num_cmonth` else echo "" fi if [ $duration -gt $interval ] then rm -rf $name fi echo ok done