Below is a simple script that searches for files older than 30 days, then returns the number of files, or ZERO.
I'd like it to do the following, if possible:
- exit from the loop if it finds anything older than 30 days, and moves to the next line in list.dat
This way, it won't have to recurse further through someone's directory since we've found what we're looking for, as some of these directories are huge and we're using an aging SAN so it's glacial.
We're basically trying to generate a report of 'home' folders that have been idle for more than 30 days, but cannot extract this info via any other way than this.
I don't believe there is any way to capture the exit status of 'find' to make this any easier...
Or, if anyone has a suggestion on how to do this differently, I'm all ears.
Any suggestions, ideas or help much appreciated!
Dan
#!/bin/sh
PATH=/bin:/usr/bin:/usr/sbin export PATH
SOURCEDIR=/Volumes/UserHomes/
while IFS= read -r line
do
COUNT=$(find $SOURCEDIR/$line -type f -mtime -30 | wc -l)
if [ "$COUNT" -eq 0 ]; then
echo $line ZERO
else
echo $line $COUNT files found
fi
done < $SRCLIST