Akex's suggestion will work for whole files, but I'm not sure that's what you meant? Are you trying to remove entries over two months old from within the files, leaving entries after that period intact?
mail are stored in a unique file per user ... the only way is to write something which can read the mailbox file .... but this is a privacy violation .... not very legal ... really dangerous by the legal view point for you (if mail in these mailboxes are something human related)
#!/usr/bin/ksh
cd /var/spool/mail
MBOXES=$(ls)
for USER in $MBOXES
do
nmess=$(echo q|mail -f $USER|grep $USER|grep messages|grep unread|awk '{print $4}')
if [ x$nmess != "x" ];then
echo f1-$nmess|mail -f $USER|tr -s " "|cut -d" " -f1-7 > messages_header.$USER
fi
done
In the messages_header.$USER you will have only the number of the messages, the sender and the date of sending .... then you will have to extract the list of "aged message" and kill them by doing something like:
from=1st_message_to_kill
to=last_message_to_kill
echo "d${from}-${to}" > kill_messages.$USER
echo "q" >> kill_messages.$USER
mail -f $USER < kill_messages.$USER
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.