#!/bin/ksh ## $Id: take-out-trash,v 1.3 2003/02/14 20:52:52 shaug Exp $ # # take-out-trash: remove all the old messages from the user mailboxes # "Trash" and "Junk". ## # How long do we want to keep email? Anything older will be removed. TRASH_AGE='1 week ago' JUNK_AGE='1 week ago' ## Diagnostics: ## set to '-n' to disable trash removal ## set to '-v' to get verbose output; add -v's to get more info #DEBUG_TRASH="-n -v" #DEBUG_JUNK="-v -v" PATH=$PATH:/usr/local/adm/bin # delete old Trash messages from /usr/mail locate /usr/mail/*/Trash | xargs trash-monkey $DEBUG_TRASH "$TRASH_AGE" echo "Checking ownership of Trash mailboxes..." awk -F: '{ print $1,$3,$4,$6 }' /etc/passwd | while read l u g h; do mbx=`echo $h |sed 's,/home,/usr/mail,'`/Trash [[ -f $mbx ]] || continue bad=`find $mbx \! -user $u` [[ -z "$bad" ]] && continue ls -l $bad chown $u:$g $mbx chmod 0600 $mbx ls -l $bad done # delete old Junk messages from user home directories awk -F: '/^[^#]/ && $4 ~ /^(10|14|30|501|502|2080)$/ { print $6 }' /etc/passwd \ | while read home; do # skip if there's no Junk file [[ -f $home/mail/Junk ]] || continue #has_junk=$(find $home/mail/Junk \! -size 504c) #[[ -n "$has_junk" ]] || continue trash-monkey $DEBUG_JUNK "$JUNK_AGE" $home/mail/Junk done echo "Checking ownership of Junk mailboxes..." awk -F: '{ print $1,$3,$4,$6 }' /etc/passwd | while read l u g h; do mbx=$h/mail/Junk [[ -f $mbx ]] || continue bad=`find $mbx \! -user $u` [[ -z "$bad" ]] && continue ls -l $bad chown $u:$g $mbx chmod 0600 $mbx ls -l $bad done