I'm trying to basically look at a directory that has sub-directory for each user. Say user1 and user2 and so on. I want to basically go through each directory and look for files older than a certain date and log it. I'm able to get a list of directories with ls -d /directory/*/. I know I can use find ./ -type f -mtime +30 to look for files that haven't been modified more than 30 days. I'm having trouble figuring out how to use the find so each time through it will look at like find ./user1 -type f -mtime30 and then ./user2 and so on.
#!/bin/bash
LIST="$(ls -d /Volumes/db_backups/*/)"
for i in "$LIST";do
fold=`basename $i`
echo $fold
ModList=$(find $i -type f -mtime +30 >$fold.out )
$ModList
done
Update: I was able to get a list of files. However, I want to not loop through a specific sub-directory and to email each user. For instance, I have a file being logged like /dir1/dir2/user1/file.txt. How would I grab the user1 list and put it in a user1.out and then user2.out and so on?
basename $iSo basically I want to create output files for each subdirectory that has a list of files older than x days. Then I think I can basically email each output file to each user.