Solved

Automatic clean up of var/spool/mqueue

Posted on 2014-01-19
5
2,464 Views
Last Modified: 2014-01-19
What are files in the /var/spool/mqueue and what are its purpose? Please create me a one-liner script to regular delete these files if not needed in the cron
0
Comment
Question by:oo_tatang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 19

Expert Comment

by:bevhost
ID: 39792744
Create a file in /etc/cron.monthly (or weekly, daily) which contains...
/bin/rm -f /var/spool/mqueue/*
0
 
LVL 19

Expert Comment

by:bevhost
ID: 39792745
These are actually mailboxes.  to read the mail you can type mail at the prompt to read the mail for the user you are logged in as. man mail for help.
Most mail for root comes from cron jobs that run.
0
 
LVL 9

Accepted Solution

by:
gt2847c earned 500 total points
ID: 39792873
The files in /var/spool/mqueue are mail messages queued to be sent.  If you just kill all the files in that directory, you may be wiping out legitimate mail that hasn't been sent either due to delivery problems, or just hasn't been picked up by the mail program.  Most mail senders (sendmail, postfix, others) have a configured max retry time for attempts to resend previously undelivered mail (5 days is a common setting).  So if you want to clear out the entries in this directory that are most likely dead mail, you should kill files older than your max retry time.

A one liner that can be added to a Cron job would be:

/usr/bin/find /var/spool/mqueue -mtime +6 -exec /bin/rm -f {} \;

Open in new window


That will find anything in the /var/spool/mqueue directory that hasn't been modified for 6+ days and remove it.

You can either add to a cron file  as mentioned by bevhost above or you can simply create a cron table entry for an account that has sufficient privileges (root):

crontab -u root -e

Open in new window

and then add the line:
0 0 * * * /usr/bin/find /var/spool/mqueue -mtime +6 -exec /bin/rm -f {} \;

Open in new window

which will run midnight every night to clear out old files from the directory.
0
 

Author Closing Comment

by:oo_tatang
ID: 39793040
The files are owned by root:smmsp . What should I do now? Do I need to regularly delete or reduce hold time to +4 or how will i know these mail messages are important since the server is just a cell manager for backups
0
 
LVL 9

Expert Comment

by:gt2847c
ID: 39793167
You can adjust the -mtime parameter to suit your needs, but it should be configured to be longer than the maximum retry/queue time for your system mailer.  That said, the mailer program on your machine should, if it's running properly, remove the queued message files once a message is successfully delivered.  You shouldn't have to clean up the /var/spool/mqueue directory very often yourself unless there is a problem.  If your system is stacking up large numbers of files in the mail queue directory, you probably need to find out why.  

As to what the messages are, and why they're there, you may need to look at the files there and see what's in them. Many *nix systems use mail to notify of job completion, status, failures, etc.  Mail from automated systems that don't have mailboxes (i.e. sender address is not a valid local or remote account), that get bounced (invalid recipient address) may end up being left behind in the mqueue directory.  Those would need to be cleaned up, but before just killing them all off, you should try and determine what it is that is sending mail to non-existent recipient (assuming that's the problem) so that it can either be configured correctly or stopped from sending.

Be advised, that depending on who owns the server and company policy, you might need to get permission before poking through mail files (just an FYI - some HR folks get upset about this especially if there are any sensitive messages floating about).
0

Featured Post

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question