qmail is one of the most popular MTA’s in the world. I am addicted to it since I found lifewithqmail.org, an step-by-step guide on installing qmail.

There are some tools that let you work with qmail’s queue (qmail-qread, qmHandle, etc.), but none of them gives you an idea of the amount of data queued for sending. This is an issue when you have your own server in your home network because the overall perfomance of your Internet connection will be affected by the traffic waiting to be sent in the MTA’s queue.

The script is quite simple. In fact, it isn’t, so I will try to explain myself.

#!/bin/sh

qread="/var/qmail/bin/qmail-qread"

len=`$qread | wc -l`
mails=0
totalsize=0

for i in `seq 1 $len`;
do
    line=`$qread | head -n $i | tail -n 1`
    newmail=`echo $line | grep ">" | wc -l`
    if [ $newmail -eq 1  ]; then
        mails=$((mails+1))

        let recipients=0;
        mailsize=`echo $line | awk '{print $7}'`

        let k=i+1
        #count recipients
        for j in `seq $k $len`;
        do
                dest=`$qread | head -n $j | tail -n 1`
                newmail=`echo $dest | grep ">" | wc -l`
                if [ $newmail -eq 0 ]; then
                        if [ `echo $dest | grep done | wc -l` -eq 0 ]; then
                                let recipients=recipients+1
                        fi
                else
                        break
                fi
        done

        msjsize=$((mailsize*recipients))
        let totalsize=totalsize+msjsize
    fi

done

totalsize=$((totalsize / 1024 / 1024))
echo "messages in queue: $mails"
echo "total queue size: $totalsize M"

First of all, the script runs qmail-qread to get information of the queue. Then, it starts processing it. For each message it finds (searching for the < character) counts the number of recipients. Then it adds the (message size * recipient number) to the total amount of data already stored in totalsize.

Finally the scripts displays it’s results in two lines: the messages in the queue and total size of the queue.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Slashdot
  • Technorati