Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleting old files using a while loop

Status
Not open for further replies.

jalge2

Technical User
Feb 5, 2003
105
US
Alright folks, here's the situation. We have files out there with naming conventions such as *.20030303 (Year Month Day only with expressions). We have a lot of them also, and my job is to clean this up with a script that I am going to put in the crontab. I'm deleting files 7 days or older. I can get the script to delete the file that is exactly 7 days old, but I can't get the loop to subtract one and run it again to delete files that are 8 days old, and so on. Here is my script. I would appreciate any help I get. #!/bin/ksh
+2 ###VARIABLES###
+3 date1=`date +%Y%m%d`
+4 date2=`expr $date1`
+5 less=$(($date2 - 7 ))
+6 less1=$(($less - 1 ))
+7 ##SCRIPT###
+8 cd /dso/mis/scripts/delhislog
+9 while [[ $less > $less1 ]]
+10 do
+11 rm *.$less1
+12 done
+13 expr=`$less1 - 1`
+14 return


Please HELP!!!. Thanks a lot.

Jason Alge


 

find /dirname -name "yourfile.????????" -mtime -7 -exec rm {} \;

Look in the manual ( man find)
HTH

Dickie Bird (:)-)))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top