A Batch job to delete files from various directories

Hi,

I have a shell script to find files older than 'X' days ($2) in directory path ($1) and delete them.

Like this:
my_file_remover.sh /usr/home/c 90

Now, I need to modify this script and add it in CRON, so that it checks other directories also.

Like:
my_file_remover.sh /usr/home/c 90
my_file_remover.sh /usr/home/c++ 60
my_file_remover.sh /usr/home/sql 54

I am thinking about having a single cron entry with the input parameters put some where (say a config file), where I will be able to remove them all through a single cron.

Any ideas to go ahead about it?

Thanks in advance.

Hi,
Here's a idea, wrapper.sh

while read dir age
do
        echo Cleaning $dir +$age ...
        my_file_remover.sh $dir $age
done < /path/to/oneconfig/file

Put wrapper.sh in cron and you're done. :slight_smile:

Thanks Andryk... :slight_smile:

You can use something like this with a loop:
This will remove files that are at least 5 days old.

#!/bin/bash
DAYS=5
DIR="/var/mydir"

find $DIR/* -mtime +$DAYS -exec rm -rf {} \;