Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cleaning Mail Spool files

Status
Not open for further replies.

sivatek

MIS
Jun 7, 2004
12
SG
Hi

I would like to clean the mail boxes of users in /var/spool/mail in my RS6000 boxes.

Can anyone tell me, is there any script/tool which can remove the mails which are 2 months old.

Please advice.

Thanks
Siva
 
you may like to examine the find command along with the mtime option

Alex
 
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?
 
Hi

I want to remove the entries which are 2 months old, rest of the file should be intact

Thanks
 
find /var/spool/mail -name "*" -mtime +60 -exec rm {} \;
 
Hi
I need to redirecting root´s mail talking about enviromental problem to an external SMTP server (Lotus Notes account).
How can I do this?

OS version = 5100
Regards
[bigears]

HS

 
create a file /.forward containing the mail address.

regards,

Guillaume.
 
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)
 
you can try something like this:

#!/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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top