Wednesday, March 22, 2017

qmail Queue Monitor via Shell Script

It is must required task for a mail administrator to monitor mail queue and take required necessary steps. Due to over queue size regular mail flow might get hampered. Any particular person may abuse your SMTP server by unauthorized email marketing. In those cases, mail administrator needs to check the queue size and take actions accordingly.


In following script we will try to get qmail queue information. qmHandle is a handy command for doing this.

Objective: Receive qmail queue information in my email address

Here is a simple bash script. In this script, we will receive qmail queue statistics like below:

/service/qmail-send: up (pid 6185) 16506 seconds
/service/qmail-send/log: up (pid 6186) 16506 seconds
/service/qmail-smtpd: up (pid 6197) 16506 seconds
/service/qmail-smtpd/log: up (pid 6198) 16506 seconds
/service/qmail-smtpds: up (pid 6187) 16506 seconds
/service/qmail-smtpds/log: up (pid 6193) 16506 seconds
/service/qmail-pop3d: up (pid 6195) 16506 seconds
/service/qmail-pop3d/log: up (pid 6196) 16506 seconds
messages in queue: 2788
messages in queue but not yet preprocessed: 0

In addition, we will receive another 2 mail which will contain all mails in queue with "From" address and "Subject"


#!/bin/bash
/usr/sbin/qmHandle -l|grep Subject|sort| uniq -c|sort -n > /script/queue-subject.txt
/usr/sbin/qmHandle -l|grep From|sort| uniq -c|sort -n > /script/queue-from.txt
/usr/bin/qmailctl stat > /script/queue-stat.txt
/usr/bin/mailx -s "qubeemail queue from" didar.sust@gmail.com < /script/queue-from.txt
/usr/bin/mailx -s "qubeemail queue subject" didar.sust@gmail.com < /script/queue-subject.txt
/usr/bin/mailx -s "qubeemail queue stat" didar.sust@gmail.com < /script/queue-stat.txt

Add this script in crontab as per required schedule interval.

Cheers ✌☺

This article is dedicated to Sandy 👍

No comments:

Restore Archived Log into VMware Aria Operations for Logs (formerly known as vRealize Log Insight - vRLI)

As we cannot keep all logs in searchable space in vRLI production system due to performance and slowness issue, it is always recommended to ...