To run a job for every one hour and ...

Hi,

Someone please help me to run the script to maintain a Job: Which can be run for every one hour and should maintain the last two hours files only. It should delete the rest of the files in a dir.

Please suggest me with the sample script.

Thanks !!

Reagrds,
Rama

Have you tried utilizing CRON job?

I didn't try it. Please guide me on this.

Try Google and you find post like this:
HowTo: Add Jobs To cron Under Linux or UNIX?

Hello,

use crontab with find and exec rm

for example (based on your distri) :

find /<path to your files> -name * -mmin xyz -exec /bin/rm -f '{}' \;

For example:

find . -mtime 0 # find files modified between now and 1 day ago
# (i.e., within the past 24 hours)
find . -mtime -1 # find files modified less than 1 day ago
# (i.e., within the past 24 hours, as before)
find . -mtime 1 # find files modified between 24 and 48 hours ago
find . -mtime +1 # find files modified more than 48 hours ago

find . -mmin +5 -mmin -10 # find files modified between
# 6 and 9 minutes ago

Regards

If you, yourself, the person for whom this task matters, cannot be bothered to try, why should any of us invest our time? Especially when there is no indication that you have taken any initiative to read the cron-related manual pages, or to search the web for a tutorial, or even to write a single line of code as a first attempt at a solution.

You'll find that most members are more willing to devote their valuable time to those that help themselves. Read some of the documentation, make an attempt to solve the problem, demonstrate this by posting your script and error messages, and we will be happy to help you with specifics.

Regards,
Alister

2 Likes