Question

Does it make sense to create a script like this or is it possible that the spool files can get corrupted?

I want to be able to control the maximum mail spool file size to 500MB or keep it for a month, archive the rest, whichever comes first:

/var/spool/mail/* {
monthly
size 500M
missingok
rotate 24
notifempty
sharedscripts
}
Was it helpful?

Solution

I didn't use logrotate for this. What I did instead was redirect the spool files to /dev/null to clean them out. I also stopped my email service before and started it after the cleanup. You can tailor this as you wish

echo "emailclean.sh starting on $(date)"
echo "Stopping fetchmail service"
#/sbin/initctl stop <service>
pkill fetchmail
sleep 10
echo "Cleaning up old mail"
cat /dev/null > /var/spool/mail/root
cat /dev/null > /var/spool/mail/webalert
sleep 10
echo "Starting fetchmail Service as user webalert"
sudo -u webalert /usr/bin/fetchmail
#/sbin/initctl start <service>
echo "Cleanup Complete! /var/spool/mail/root and webalert files sent to dev0"
echo "emailclean.sh finished cleanup on $(date)"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top