Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 20th, 2003, 04:33 PM
thedarkzone's Avatar
thedarkzone thedarkzone is offline
linux addict
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: proxima centauri
Posts: 13 thedarkzone User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question bash script to determine the age of a file

hi @ all!

here's the problem: our mailserver needs cleanup, he uses qmail and virtual hosts. the mails are stored in folder tree like that:

/home/virthosts/foo_host/foo_user@foo_host/cur/foo_mail

now every mail is stored on the server and the folders get stuffed with rubbish nobody needs any more. so i got the job to write a bash script to delete mails, that are older than 30 days to include into the cron-job. this scipt is working well, it enters the directories right and deletes the files, but:

i wasn't able to find out how to determine the age of a file so the script deletes only the right files!

anybody any idea?

regards, thedarkzone

Reply With Quote
  #2  
Old March 21st, 2003, 09:38 AM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
Have a look at the "find" command. ("man find")

It can find files that are older than a given date. One comment: Donīt pass itīs output to "xargs" because on some systems it does not escape spaces in filenames. use the "-exec" switch or directly "-delete" instead.
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > bash script to determine the age of a file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway