11

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.

  • 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. – dmp 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. – dmp Aug 18 '10 at 13:49
26

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.

  • 1
    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
13

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

mailq | tail -n 1
  • 2
    That's a nice idea, but the queue is massive, so it take's a long time to return a result. Anything faster..? – dmp 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 ;) – dmp Aug 18 '10 at 13:45
3

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
1

This is

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

good idea, but it doesn't work if my Zabbix-Agent isn't run as a root. So I used this

NUM=`mailq | grep -E "Requests" | awk '{print $5}'`; if [ -z "$NUM" ]; then echo "0"; else echo $NUM; fi

for my own UserParameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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