Users don't check mail on most of my systems. I don't do it off days but do it off size. If the mailbox is over a specific size (25000) then purge everything except the last 1000 messages.
cleanmailbox.sh
------------------------------
#!/bin/ksh
HOSTNAME=`hostname`
LIST=$(find /var/spool/mail -size +25000 -ls|awk -F"/" '{print $NF}')
for USER in $LIST; do
echo $USER
ls -la /var/spool/mail/$USER
find /var/spool/mail/ -name $USER -mtime +365 -exec cp /dev/null /var/spool/mail/$USER \;
su $USER -c /usr/local/etc/cleanmailbox.dat
ls -la /var/spool/mail/$USER
done
cleanmailbox.dat
------------------------------
#!/bin/ksh
MAILCOUNT=1000
printf "\nMail count: "
echo f|mail|tail -1|awk '{print $2}'
echo Cleaning Mailbox...
echo d1-$(let num="$(echo f|mail|tail -1|awk '{print $2}')-$MAILCOUNT";echo $num)|mail >/dev/null
printf "\nMail count: "
echo f|mail|tail -1|awk '{print $2}'
------------------------------
Vinny
------------------------------
Original Message:
Sent: Fri June 10, 2022 11:22 AM
From: Sylvain
Subject: purge mails older than x days
Hi all,
how can I purge mails older than x days on AIX ?
I want to schedule this kind of task via crontab.
Thanks in advance for your help.
------------------------------
Sylvain
------------------------------