LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Auto delete mails from postfix server after 1 month (https://www.linuxquestions.org/questions/linux-newbie-8/auto-delete-mails-from-postfix-server-after-1-month-815362/)

oduori 06-21-2010 03:36 AM

Auto delete mails from postfix server after 1 month
 
How do I make my postfix mail server auto delete mails from user mailboxes after say 1 or 2 months?

manorina 07-18-2010 08:50 AM

Hi Oduori,

I would suggest that you could do this with a cron job. cron is a program which can run other programs periodically. You could write a very short shell script which finds files (those files being mail messages you want to delete) which are older than 1 month and then delete them. You can then run the shell script every day as a cron job for user root.

This will delete files older than 30 days old

Code:

find /path/to/mailmsgs -mtime +30 -delete
*BEWARE* - test this code on unimportant files first, otherwise you can get a nasty shock and lose files.

Put this code in a scripts file, let's call it rm_old_mail.sh

Using crontab -e you can create a cron job for user root. Just google crontab examples to get some information on how to use cron. Then you would run the rm_old_mail.sh script everyday at 1am, for example.


All times are GMT -5. The time now is 09:58 AM.