Advice required shell script

Hi all, this is my first post, so please be gentle...

I have a situation wherby I need a script that traverses known paths. Check for the modified date (n days) and then deletes all subdirs.
I have come up with this hotch potch, but as far as I can tell it seems to work.
What I am wondering is there any other way to make this cleaner?
Any help would be appreciated.
Oh this is on a QNAP NAS (busybox I think)

Create 2 files

  1. Includes-file (this contains all the path statements.i.e. /path1/subdir /path2/subdir/subdir etc)
  2. The script itself (del.sh)

Here is the script:

#!/opt/bin/bash
# cat all paths to cd
for i in `cat includes-file`;do
# find all directories in paths that have been modified more than 70 days ago and then delete them
cd $i; for path in `/opt/bin/find . -maxdepth 1 -mtime +70` ; do rm -rf $path
done
done

Cheers in advance.

for i in `cat includes-file`;do

is wrong. See: BashPitfalls - Greg's Wiki
This is cleaner:

while read p; do
  find "$p" -type d -mtime +70 | xargs printf "rm -rf %s\n"
done <includes-file

After checking that everything is ok, change "xargs ..." to "xargs rm -rf"

a little more cleaner... :wink:

while read p; do   find "$p" -type d -mtime +70 -delete
done <includes-file

--ahamed

And how '-delete' works with non-empty directories? :rolleyes:

Thank you both Yazu and Ahamed101.

I have put in Yazu's code, tested and works. I had a programmer at work explain the finder points of your script. I have never used "read" before.
Final code:

#!/opt/bin/bash
while read p; do
  find "$p" -maxdepth 1 -type d -mtime +60 | xargs "rm -rf %s\n"
done <includes-file

Once again, thank you for taking the time to look at this issue. It will be a big help to our organisations rolling backup regime.