cron may not be calling your shell. echo $SHELL to find out your shell, and put SHELL=/bin/whatever in your first line.
A few notes:
-name '*': Why have this at all?
-mtime: read the fine print... it only matches if it is exactly 7 days old. Yeah, I have no idea when that would be useful, but there is a practical solution.
-exec rm -Rf {} \; : Doing a recursive deletion while find is recursively searching may screw up find, as in, it might be expecting those subdirectories to be there. I'd put -prune after it so find doesn't try to do that. It's also *so* easy to blow up your whole system, be careful.
find generally: Do you really need to search every file, or are you just trying to delete the directories right under archivelog? You can use -maxdepth 1 if you really want to use find, but don't need recursive searching.
Since -mtime isn't doing what you want, you could replace it with -not \( -mtime 7 -o mtime 6 -o -mtime 5 ... \)
But I'd suggest:
Code:
#!/bin/bash
lastweek=`date -v-7d '+%Y%m%d'`
for d in *
do if [ `stat -t '%Y%m%d' -f '%Sm' "$d"` -lt "$lastweek" ]
then echo rm -rf "$d"
fi
done
The echo command will simply show what it's trying to delete. This, incidentally, doesn't hunt through directories, making it a good bit safer.
The -v command to date tells it to report the date minus 7 days. You'll notice the %Y%m%d format string; that's using a standard library call to format so both date and stat are producing the same thing. By putting (4-digit) year first, month second, day last, you get a value that can be compared numerically.
The stat command gets information about a file, in this case, the formatted modification time.
If you wanted, alternately, to scan based on file name, this would work:
Code:
#!/bin/bash
lastweek=`date -v-7d '+%Y_%m_%d'`
for d in ????_??_??
do if [ "$d" < "$lastweek" ]
then echo rm -rf "$d"
fi
done
Here I'm using the ????_??_?? pattern to make sure I'm only matching entries that make sense. And the < does a string comparison, which also happens to work with dates formatted that way.