
23rd June 2006, 00:18
|
|
Junior Member
|
|
Join Date: Jun 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
shell script
Hello,
Sorry for the noob question could not find an answer for this.
I need a shell script that I can run in cron that will search one or more folders for specified file(s) and delete them if they are older then (ex: ) 10 days.
Thank you
|

23rd June 2006, 08:06
|
|
Member
|
|
Join Date: Feb 2006
Posts: 65
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Look up the documentation for find:
You can for example search for files that were accessed (read) 10 days ago or more with:
Code:
find . -name '*tmp*' -atime +9
(Note that it's 9 not 10!)
With
Code:
find . -name '*tmp*' -atime +9 -delete
You delete them.
You can just put that line directly into the cron or in a shell script if you have to.
Note: "." is the current working directory. If you want to change it do so ;-).
__________________
Always mention at least your distribution/version! You can add it in your signature if you don't want to always type it. ;-)
Distributions:
Ubuntu 5.10 with custom kernel (2.6.16-suspend2),
Debian Sarge 3.1 and Etch
Please submit your ISP or Webhost to (free)
http://www.ihostnz.com
|

23rd June 2006, 19:09
|
|
Junior Member
|
|
Join Date: Jun 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
geek.de.nz,
Thank you for the info, never knew you could put something like this right in the cron! I'm guessing I would have to put the complete path since I don't know what the current working directory would be for cron (if i put this right inside the cron).
You've got me curious now can you actually run scripts inside cron? Are there any limitations to this?
|

23rd June 2006, 22:51
|
|
Junior Member
|
|
Join Date: Jun 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok when i enter this line;
find . -name '*.tar.gz' -atime +9 -delete
I get this error:
find: invalid predicate `-delete'
|

24th June 2006, 14:47
|
|
Super Moderator
|
|
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 31,853
Thanks: 781
Thanked 1,558 Times in 1,477 Posts
|
|
Have a look at
Quote:
|
Originally Posted by Nnyan
geek.de.nz,
Thank you for the info, never knew you could put something like this right in the cron! I'm guessing I would have to put the complete path since I don't know what the current working directory would be for cron (if i put this right inside the cron).
You've got me curious now can you actually run scripts inside cron? Are there any limitations to this?
|
To create a cron job that runs your tasl at 05:00h each day (for example), run
(as root) and enter this:
Code:
0 5 * * * find . -name '*tmp*' -atime +9 -delete
Instead of just find you can use the full path to find, e.g. /usr/bin/find. Run to find out where find is on your system.
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +2. The time now is 14:20.
|
Recent comments
19 hours 54 min ago
1 day 12 min ago
1 day 5 hours ago
1 day 11 hours ago
1 day 11 hours ago
1 day 11 hours ago
1 day 12 hours ago
1 day 14 hours ago
1 day 16 hours ago
1 day 17 hours ago