Automated Mail Purging for SMTP Mail
Copy the scripts to your favorite directory. I used /usr/local/bin. Edit mailrm.sh and mailage.sh to reflect your mail directory and the location of formail. Then just run the script with the number of days to retain messages as its argument. For example, to purge messages older than 60 days:
Is this mail purge solution perfect? No, it does nothing to lock mail files, which could pose a problem if a user's mail client polls frequently or this job runs during busy hours. Some possible steps to address this could include stopping sendmail while the scripts run, preventing the POP3 server from running and tightening permissions on the mail directory to prevent access from non-superusers. Since it would normally run in the early-morning hours via cron, the probability of collision would be low.
Also, this solution relies on external utilities that may not function as expected. formail might not properly handle all the mail headers, though I haven't encountered problems yet. cat might not like some characters that could appear in messages, resulting in lost message text. I've had few problems with cat, but your experience may be different.
The date conversion logic in maildate.sh is simplistic. It's not accurate for the year 1900, and the leap year calculation will not work correctly after the year 2099. However, it works well for calculating the difference between two dates, and it's reasonably fast.
Since I use three scripts to get around parameter-passing limitations in Bash, this package runs more slowly than it might (because of having to fork processes repeatedly). Recoding the scripts into a single Perl script might help—my Perl skills are too limited for this project.
If you have a need for automated mail purging, these scripts can help you reach your goal. At least, they may give you ideas for your own solution. If you create a more elegant solution, I'd like to hear about it.
All listings referred to in this article are available by anonymous download in the file ftp://ftp.linuxjournal.com/lj/listings/issue47/2118.tgz.
Michael S. Keller (email@example.com) is a Technical Analyst with Paranet, Inc., a nation-wide network services provider owned by Sprint. He has used computers for twenty years and Unix variants for seven. Paranet's virtual home is at http://www.paranet.com/.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Petros Koutoupis' RapidDisk
- ServersCheck's Thermal Imaging Camera Sensor
- The Italian Army Switches to LibreOffice
- Linux Mint 18
- Oracle vs. Google: Round 2
- The FBI and the Mozilla Foundation Lock Horns over Known Security Hole
- Privacy and the New Math
- Varnish Software's Varnish Massive Storage Engine
Until recently, IBM’s Power Platform was looked upon as being the system that hosted IBM’s flavor of UNIX and proprietary operating system called IBM i. These servers often are found in medium-size businesses running ERP, CRM and financials for on-premise customers. By enabling the Power platform to run the Linux OS, IBM now has positioned Power to be the platform of choice for those already running Linux that are facing scalability issues, especially customers looking at analytics, big data or cloud computing.
￼Running Linux on IBM’s Power hardware offers some obvious benefits, including improved processing speed and memory bandwidth, inherent security, and simpler deployment and management. But if you look beyond the impressive architecture, you’ll also find an open ecosystem that has given rise to a strong, innovative community, as well as an inventory of system and network management applications that really help leverage the benefits offered by running Linux on Power.Get the Guide