#1  
Old 23rd June 2006, 00:18
Nnyan Nnyan is offline
Junior Member
 
Join Date: Jun 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote
  #2  
Old 23rd June 2006, 08:06
geek.de.nz geek.de.nz is offline
Member
 
Join Date: Feb 2006
Posts: 65
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to geek.de.nz Send a message via MSN to geek.de.nz
Default

Look up the documentation for find:
Code:
man 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
Reply With Quote
  #3  
Old 23rd June 2006, 19:09
Nnyan Nnyan is offline
Junior Member
 
Join Date: Jun 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?
Reply With Quote
  #4  
Old 23rd June 2006, 22:51
Nnyan Nnyan is offline
Junior Member
 
Join Date: Jun 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok when i enter this line;

find . -name '*.tar.gz' -atime +9 -delete

I get this error:

find: invalid predicate `-delete'
Reply With Quote
  #5  
Old 24th June 2006, 14:47
falko falko is online now
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 31,853
Thanks: 781
Thanked 1,558 Times in 1,477 Posts
Default

Have a look at
Code:
man find
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
Code:
crontab -e
(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
Code:
which find
to find out where find is on your system.
__________________
Falko
--
Follow me on:
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help for writing shell script chris_87 Programming/Scripts 7 4th April 2007 16:50
ftp shell script mcrosby Programming/Scripts 8 9th January 2007 16:12
ping script mcrosby Programming/Scripts 12 9th January 2007 00:27
Need help for writing shell script erez Programming/Scripts 4 16th June 2006 15:23
Shell script is broken... Duplex Installation/Configuration 4 16th January 2006 10:55


All times are GMT +2. The time now is 14:20.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Sponsored Links: Unified Communications: Thoughts, Strategies and Predictions
Join the discussion.
www.seamlessenterprise.com

IP Convergence
Integrate your wireless and wireline networks.
Learn how from the experts at Sprint.
www.seamlessenterprise.com

Wireless & Wireline Integration
Thoughts, strategies and solutions: join the discussion
www.seamlessenterprise.com

Unified Communications 2009
Join the Discussion. Now.
www.seamlessenterprise.com

Red Hat Virtual Experience - a free virtual event. Dec. 9th