Solved

Automatic clean up of var/spool/mqueue

Posted on 2014-01-19
5
2,198 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
  • 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now