#!/bin/bash if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi source /a/bin/errhandle/err source /a/bin/bash_unpublished/source-state if [[ $HOSTNAME != "$MAIL_HOST" ]]; then exit 0 fi # find but ignore directories which dont exist, assuming first args are directories # and a following arg starts with - myfind() { dirs=() for d; do if [[ $d == -* ]]; then # past dirs, onto options break fi shift if [[ -e $d ]]; then dirs+=($d) fi done if (( ${#dirs[*]} )); then find ${dirs[@]} $@ fi } # qemu-devel is our biggest list by far, so occasionally # I want to hop into conversations about our mailing # systems there, but I don't need many old messages. myfind /m/md/l/qemu-devel/new -type f -mtime +14 -execdir rm -- '{}' + myfind /m/md/l/listhelper-moderatre/new -type f -mtime +14 -execdir rm -- '{}' + myfind /m/md/{sec,Spam,Drafts,{rtcc,sysadmin}/new} -type f -mtime +100 -execdir rm -- '{}' + myfind /m/md/log -type f -mtime +300 -execdir rm -- '{}' + myfind /m/md/dmarc -type f -mtime +60 -execdir rm -- '{}' + myfind /m/md/fsfalerts -type f -mtime +10 -execdir rm -- '{}' + # not strictly a mail directory, but it fits well in this script myfind /p/c/.editor-backups -type f -mtime +300 -execdir rm -- '{}' + shopt -s nullglob shopt -s extglob archive() { days=$1 shift for d; do [[ -d $d ]] || continue leafdir=${d##*/} # cur/new archivebase=${d%/*}-myarchive archive=$archivebase/$leafdir mkdir -p ${archivebase}/{cur,tmp,new} find $d -type f -mtime +$days -name '1*' -exec mv '{}' $archive \; # count=$(find $d -type f -mtime +$days -name '1*' | wc -l) # if (( count )); then # echo $d $count # fi done } cd /m/md archive 800 ./!(*archive|Drafts|Sent|INBOX)/*(cur|new) ./l/!(*archive)/*(cur|new) archive 60 ./{sysadmin,rtcc,fsfcc,fsfmembers}/{cur,new} archive 14 ./Junk/{cur,new}