I've totally hacked together this script and I hope to get some corrections, or some insight into a much simpler version which I know is possible...
I want to loop through a named dir and check each subdir if it contains any subdirs that are X minutes old, and if so delete the old subdir. Each eligible subdir will only contain 1 symbolic link.
For this structure /var/www/flash/avmin/{$usr_id}/{$timestamp}/{->symlink}
I want to preserve /{$usr_id} but delete all /{$timestamp} if +12 hours old, and I assume this means I need to empty it before deleting it.
Because it is likely that /{$usr_id} will be created in the same server instance when $timestamp and the symlink are created, I must loop through each /{$usr_id} subdir and test conditions from there.
I will make this script run every 12 hours with Cron running as root, therefore within one 24 hour period all symlinks will be assured to be clean.
Note there may be several {$timestamp} subdirs in ../{$usr_id}, but each subdir will contain only 1 symlink and nothing else.
I sense this could be one or two lines of code without the for...in and simply using find inside avmin using (-maxdepth 2) and a time condition of X hours (or X mins) right???
#!/bin/bash
for i in /var/www/flash/avmin/*
do
cd "$i"
for xdir in "$i"
do
if [ "$xdir" type d -cmin +60 ]; then
find . -maxdepth 2 -type L -cmin +60 -exec rm {} \
"$xdir" -type d -cmin +60 -exec rm {}
fi
done
done
exit
I saw a "similar question" which has given me an idea here