I have to write one script which will delete the files in the below passion.
If today is 17-Feb-2010 then the script delete only 17-JAN-2010 files from the directory.
Could you please help me, How will I delete the files when the year is leap year, if today is 30th Mar 2010 then how will handle such scenarios.
I have written simple script for getting the yesterday's date but I do not understand how to develop the script based on the above requirement.
bash-3.00$ cat calc_date_sample.sh
v_todaysdate=`date +%d`
v_yesterday=$((`date +%e` -1))
v_month=`date +%m`
v_year=`date +%Y`
if [ $v_yesterday -eq "0" ]
then
v_month=$((v_month-1))
if [ $v_month -eq "0" ]
then
v_month=12
v_year=$((v_year-1))
fi
set `cal $v_month $v_year`
shift $(($# - 1))
v_yesterday=$1
fi
echo "Previous Date : - " $v_yesterday-$v_month-$v_year
echo
echo "TodaysDate : - " $v_todaysdate-$v_month-$v_year
bash-3.00$
bash-3.00$
Quote:
bash-3.00$ ./calc_date_sample.sh
Previous Date : - 16-02-2010
TodaysDate : - 17-02-2010
bash-3.00$
bash-3.00$
If today is 17-Feb-2010 then the script delete only 17-JAN-2010 files from the directory.
Could you please help me, How will I delete the files when the year is leap year, if today is 30th Mar 2010 then how will handle such scenarios.
I have written simple script for getting the yesterday's date but I do not understand how to develop the script based on the above requirement.
bash-3.00$ cat calc_date_sample.sh
v_todaysdate=`date +%d`
v_yesterday=$((`date +%e` -1))
v_month=`date +%m`
v_year=`date +%Y`
if [ $v_yesterday -eq "0" ]
then
v_month=$((v_month-1))
if [ $v_month -eq "0" ]
then
v_month=12
v_year=$((v_year-1))
fi
set `cal $v_month $v_year`
shift $(($# - 1))
v_yesterday=$1
fi
echo "Previous Date : - " $v_yesterday-$v_month-$v_year
echo
echo "TodaysDate : - " $v_todaysdate-$v_month-$v_year
bash-3.00$
bash-3.00$
Quote:
bash-3.00$ ./calc_date_sample.sh
Previous Date : - 16-02-2010
TodaysDate : - 17-02-2010
bash-3.00$
bash-3.00$