Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there a simple command to find out the current number of messages in the linux mail queue? mailq dumps out a verbose list, but it's not convenient for a quick overview.

I'm using Ubuntu and postfix.

share|improve this question
1  
What mail transfer agent are you using? –  Bart Silverstrim Aug 18 '10 at 13:32
    
like bart said, tell us what MTA youre using so we can give you a more specific and correct approch. –  Prix Aug 18 '10 at 13:34
    
sendmail, sorry. –  danp Aug 18 '10 at 13:39
    
Sure it's sendmail, not postfix? Just making sure... –  Bart Silverstrim Aug 18 '10 at 13:45
    
good catch, its postfix not sendmail. –  danp Aug 18 '10 at 13:49

3 Answers 3

up vote 11 down vote accepted

If you just want to know the number of messages sitting in the deferred queue, then the following should get you a quick answer:

find /var/spool/postfix/deferred -type f | wc -l

There are three other queues. See http://www.porcupine.org/postfix/queueing.html for details.

share|improve this answer
    
in my case it was this: find /var/spool/mqueue -type f | wc -l and this find /var/spool/mqueue-rx -type f | wc -l as I have two queues and don't use postfix. –  Jeroen Wiert Pluimers Aug 16 '12 at 20:17

You could filter the output and display only the last line:

mailq | tail -n 1
share|improve this answer
1  
That's a nice idea, but the queue is massive, so it take's a long time to return a result. Anything faster..? –  danp Aug 18 '10 at 13:38
    
If the queue is really really massive, there may be another issue (unless you're an ISP or mail hosting service). You shouldn't have a backup so huge that you have to wait a few minutes for these results...? –  Bart Silverstrim Aug 18 '10 at 13:41
    
I'm sure there is another issue, but that'll come in another question ;) –  danp Aug 18 '10 at 13:45

As a related matter, you can also obtain the number of messages in your mailbox stored in mbox format, by modifying Brian Showalter's suggestion using the command "mail --headers."  For example, I have this line in my .bashrc file:

if [ -s /var/mail/$(whoami) ] ; then echo -e "\nYou have $(ls -s -h /var/mail/$(whoami) | cut -d" " -f 1) of mail.  Number of messages: $(mail --file /var/mail/$(whoami) --headers | wc -l) ($(mail --file /var/mail/$(whoami) --headers | sed '/^>* *[0-9]/d' | wc -l) unread)" ; fi
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.