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
The scenario is, I have a bunch of wavelog files with the file names being... wavelog.20020422 (todays date)

The problem I am having with is, I'm trying to delete files that are older than seven days using the date format at the end of the filename. Here is what I have so far,


#!/bin/ksh
+2
+3 ##Variables##
+4 date1=`date +%Y%m%d`
+5 date2=`expr $date1`
+6 less=$(($date2 - 7))
+7 less1=$(($less - 1 ))
+8 ##Script##
+9
+10 cd /dso/mis/scripts/delhislog
+11 while [ "wavelog.$date2" => "wavelog.$less" ]
+12 do rm wavelog.$less
+13
+14 done
+15
+16

I am getting a test: argument expected on line 11 and I can't figure out why. Can someone help?
 
why not use find with a +7?

find /dso/mis/scripts/delhislog -name "wavelog.*" -mtime +7 | xargs rm
 
As for the conditional test error on line 11 it is because you are using a relational operator that is incorrect (=>), the correct relational operator would be >=
 
I keep forgetting things until I am done.

Another pet peeve that I continuously preach is the old [] has been replaced by the more powerful [[]] which everyone should use.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top