• Post Reply Bookmark Topic Watch Topic
  • New Topic

Shell script for deleting file in time interval  RSS feed

 
Sham Jowsaki
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
My requirement is that I have log files which will create dynamically everyday, (eg sham2003-08-12.log, jowsaki2003-08-12.log, ...) I need to keep only the 7 days ago log files.
Can you pls explain me how to do .sh file.
Thanks
Jowsaki
[ August 12, 2003: Message edited by: Sham Jowsaki ]
[ August 12, 2003: Message edited by: Sham Jowsaki ]
 
Alton Hernandez
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might consider using just one name for you log file and then use logrotate to manage it.
 
Greg Harris
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is a simple example that can be expanded. it only deletes files that are exactly 8 days old. you need a file that contains a list of the usernames.

[ August 13, 2003: Message edited by: Greg Harris ]
 
Tim Holloway
Saloon Keeper
Posts: 18792
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh tsk, tsk, tsk. I clean out old Tripwire reports every week or three with a command like the following:
find mydir -name "myfile.*" -ctime +7 | xargs rm
Deletes "myfile"s in mydir that were created over 7 days back.
For logfiles, I recommend logrotate, though. It has features that are expecially useful when managing logfiles.
 
Greg Harris
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nice... i forgot about ctime. would have made my script easier.
 
Sham Jowsaki
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for you all.. Am goin with Tim's stuff.
Once again thankful
Cheers
Jowsaki
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!