Operating System - HP-UX
1833703 Members
3504 Online
110062 Solutions
New Discussion

Re: mail command to purge mail

 
kholikt
Super Advisor

mail command to purge mail

how to purge any mail which is one month old through a command line rather than elm
abc
4 REPLIES 4
Michael Tully
Honored Contributor

Re: mail command to purge mail

Hi,

The following command will remove all files
in /var/mail that have not been modified in the last 30 days. You could change the option 'mtime' to 'atime' and this would only then remove files that have not been accessed in the last 30 days.

find /var/mail -mtime +30 -exec rm {} \;

HTH
-Michael
Anyone for a Mutiny ?
kholikt
Super Advisor

Re: mail command to purge mail

Hi,

Actually my problem is I have so many incoming mail in one of the mailbox. I just to keep one month old of the incoming mail in that particular mailbox.
abc
Michael Tully
Honored Contributor

Re: mail command to purge mail



Hi,

elm was never designed to the task that you want. elm is used to cater for individual mailboxes.

Have a look at the HP porting centre and of
course GNU, you just may find something of
use.

http://hpux.cs.utah.edu/

and

http://www.gnu.org/software/software.html

Only other suggestion I can make is to look
at commercial mail package. Only one I know of
is openmail.

HTH
-Michael


Anyone for a Mutiny ?
Steven Sim Kok Leong
Honored Contributor

Re: mail command to purge mail

Hi,

You can perform some crude but easy steps to trim your mailbox from the command line. You can also perform the below steps in a script so that you can flexibly add options to triming your mailbox.

Example, you want to clear your root mailbox and save only mails from a specific date and time.

1) Get all email timestamps for Jan 2002:

# grep "^From " root | grep " 2002$" | grep " Jan "
From root Thu Jan 17 13:01:45 2002
From root Thu Jan 17 13:16:42 2002
From root Thu Jan 17 13:31:46 2002
From root Thu Jan 17 13:46:37 2002
From root Thu Jan 17 13:50:09 2002

2) Select the email timestamp you want to start saving your emails from (in this case, Jan 17 13:46:37) and pinpoint the line number (in this case, 69817) in your mail file:

# cat -n root | grep "From root Thu Jan 17 13:46:37 2002"
69817 From root Thu Jan 17 13:46:37 2002

3) Extract your emails from the mail file starting from this line number (69817) onwards:

# tail +69817 /var/mail/root > /tmp/root.mail

4) Update your /var/mail/root mail file:

# mv -f /tmp/root.mail /var/mail/root

Hope this helps. Regards.

Steven Sim Kok Leong