Display number of messages in linux mail queue
Solution 1
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.
Solution 2
You could filter the output and display only the last line:
mailq | tail -n 1
Solution 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
Solution 4
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.
Related videos on Youtube
dmp
Updated on September 17, 2022Comments
-
dmp almost 2 years
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.
-
user1364702 almost 14 yearsWhat mail transfer agent are you using?
-
Prix almost 14 yearslike bart said, tell us what MTA youre using so we can give you a more specific and correct approch.
-
dmp almost 14 yearssendmail, sorry.
-
user1364702 almost 14 yearsSure it's sendmail, not postfix? Just making sure...
-
dmp almost 14 yearsgood catch, its postfix not sendmail.
-
-
dmp almost 14 yearsThat's a nice idea, but the queue is massive, so it take's a long time to return a result. Anything faster..?
-
user1364702 almost 14 yearsIf 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...?
-
dmp almost 14 yearsI'm sure there is another issue, but that'll come in another question ;)
-
Jeroen Wiert Pluimers almost 12 yearsin my case it was this:
find /var/spool/mqueue -type f | wc -l
and thisfind /var/spool/mqueue-rx -type f | wc -l
as I have two queues and don't use postfix. -
Scottie H almost 4 yearsJust what I was looking for. Thanks!