Quote:
Originally Posted by ramystyle
Basically, I would like to be able to delete all emails on the server that are older than 2 years.
Any scripts or way of doing this ?
|
You can simply run a find against all the standard mail folders
for mail that is older than two years:
Code:
find -P /home/*/mail/*/*/cur -mtime '+729'
find -P /home/*/mail/*/*/new -mtime '+729'
The above will give you a list of all the mail files older than two years
and you can either pipe that into 'xargs' for a very quick and dirty way
of doing that pipe into a file and then have a script parse the file to
do whatever you would like. Here is a very basic example:
Code:
#!/bin/bash
IFS="$"
cd /home
find -P /home/*/mail/*/*/* -mindepth 1 -maxdepth 1 -mtime '+729' | while read OLDMAIL; do
echo "Now deleting ${OLDMAIL} ..."
rm -f "${OLDMAIL}"
done
(Incidentally the 729 is the number of days old the file must be greater)
You could delete the "echo" line and add this basic code to a cronjob
and have your server auto delete all mail older than 2 years or
whatever length of time that you want.