Display number of messages in linux mail queue

Posted on

Display number of messages in linux mail queue – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about linux, email, queue, , .

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.

Solution :

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.

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

mailq | tail -n 1

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

Leave a Reply

Your email address will not be published.