Did you try the above code I posted?
Since then I added checking for open files. The following bash script seems to work :
Code:
#!/bin/bash
TMPMSG='/root/Tmpclean.msg'
cat /dev/null >$TMPMSG
for I in /tmp /var/tmp
do
tmpLSOF=`mktemp /tmp/SnapLSOF.XXXXXXX`
#safety kludge
if [ -z $tmpLSOF ]
then
tmpLSOF='/tmp/heyINeedToInstallmktemp'
fi
#end safety kludge
lsof > $tmpLSOF
find $I ! -type d -a -cmin +500 -print 2>>$TMPMSG | while read J
do
echo "processing found item $J"
#Check for open files before deleting from tmp
if [ 0 -eq $(cat $tmpLSOF |grep "$J" 2>/dev/null | wc -l) ]
then
echo "File $J can be deleted"
rm -v "$J"
else
echo '*------------------------------------*'
echo "File CANNOT be deleted: $J"
lsof |grep "$J"
echo '*------------------------------------*'
fi
done
echo "$0 running empty directory check in $I ..."
find $I/* -depth -type d -empty -exec rmdir {} \; 2>>$TMPMSG
done
This is run from root's cron entry specifying every 8 hours. Tweak the frequency (along with `-cmin +500' on line 8) to your style.
Caveats:
o You
must have mktemp installed to run without the kludge for the output file of `lsof'
o On some systems /var/tmp is a symlink to /tmp so a separate loop for it would be a waste.
o The echo statements are just for a sanity check. They can be safely deleted (in face the entire else stanza inside the `do' can be).
o Some might question putting the output of `lsof` into a file on /tmp, where stuff is being deleted. -cmin + <minutes> protects you.
o the `rm' on line 21
could also need the -f (force) flag.