Scripting help for rm log files from multiple dir

Hi,

I'm quite new to scripting and need some help. I need to have one script that will check specific directories for files older than one month and then have the script delete them.

I have written the script below but it only does one directory. I don't quite know how to make it so it checks other directories as well.

#!/bin/sh

DIR=/export/home/Scripts/Batch/Ds/edsf/archive
export DIR

cd $DIR;/usr/bin/find . -mtime +31 -type f | /usr/bin/xargs rm -rf

Any help would be appreciated.

Morgadoa,
See if this works for you:

find your_directory -type f -mtime +31 -exec rm -f {} \;

Thanks for your reply. I thought of the find command but I have 8 specific directories that contain files to be deleted.
Do I execute a separate find for each dir path eg.

/export/home/Scripts/logs
/export/home/GLOBAL/logs
/export/home/Batch/logs

and so on..

One find command only

cd /export/home
find Scripts/logs GLOBAL/logs Batch/logs -type f -mtime +31  | xargs rm -f

Jean-Pierre.

Here is how you do it:

mDirList="/export/home/Scripts/logs"
mDirList=${mDirList}" /export/home/GLOBAL/logs"
mDirList=${mDirList}" /export/home/Batch/logs"
for mEachDir in ${mDirList}
do
  echo "Now deleting from "${mEachDir}
  find ${mEachDir} -type f -mtime +31 -exec rm -f {} \;
done

Thanks for your help. Looks simple enough. I just wanted to confirm that the second and third line are just ammending to the variable mDirList in order to compile the list of directories- right?

Yes, you can just keep adding as many directories as you want:

mDirList=${mDirList}" other_dir01"
mDirList=${mDirList}" other_dir02"
mDirList=${mDirList}" other_dir03"
...
mDirList=${mDirList}" other_dirNN"

Great !! Thanks again for your help. :slight_smile: