#!/bin/sh
PATH=/usr/bin:/bin:/usr/sbin
export PATH
max_days=30
owner_to_keep="root nobody"
case $1 in
-ok)
owner_to_keep=$2
shift 2
;;
esac
case $1 in
[0-9]*)
max_days=$1
shift
;;
esac
dirs_to_clean=${@:-/tmp}
omit=""
for i in $owner_to_keep
do
omit="$omit ( ! -user $i )"
done
for dir in $dirs_to_clean
do
[ -d "$dir" ] &&
cd "$dir" &&
find . -depth \! -type d \( -mtime +$max_days -o -mtime -0 \) \( -atime +$max_days -ctime +5 -o -ctime +$max_days -atime +5 -o -type l \) $omit -delete -exec echo RM {} \; -o -type d -empty $omit -mtime +$max_days -delete -exec echo RMDIR {} \; 2>/dev/null
sleep 1
done
exit 0
Comments
Post a Comment