# This script cleans out /tmp of empty, root, cpanel and nobody session files in /tmp
# if --test is passed, we just show the results
if [ "$1" == "--test" ]
then
CMD="-exec ls -la"
echo "$0: test mode"
else
CMD="-exec rm -rf"
fi
# remove empty session files that are over 2 hours old
find /tmp -name "sess*" -empty -mmin +120 -maxdepth 1 $CMD {} \;
# remove root owned session files
find /tmp -name "sess*" -user root -maxdepth 1 $CMD {} \;
# remove nobody session files
find /tmp -name "*sess*" -user nobody -maxdepth 1 $CMD {} \;
# remove cpanel owned session files
find /tmp -name "sess*" -user cpanel -maxdepth 1 $CMD {} \;
# remove any session file over 4 hours old
find /tmp -name "sess*" -mmin +240 -maxdepth 1 $CMD {} \;
# remove any spamassassin file over 4 hours old
find /tmp -name ".spamassassin*" -mmin +240 -maxdepth 1 $CMD {} \;