Delete messages from mqueue and mailq

In larger organizations, your smarthost/default SMTP gateways mailq can become overloaded with unwanted and undeliverable messages. If you have enough of them, it will add a lot of CPU and disk IO load as it tries to resend/reprocess Undeliverable messages. We have a few systems that if left unchecked would try and reprocess 100K messages every 5 min. The tmp mail files are typically located /var/spool/mqueue and directly deleting these is not the correct manner and opening each one to verify deletion will likely drive you mad. I have added four scripts that will help you manage the stagnant mail you may have accumulating in your mailq. These scripts will list the mail per target address, allow you to delete mail for a single user or an entire domain.


Using the below script “”, you can determine what is causing the mailq to fill, which SMTP address and how many email messages exist in your mailq for delivery.  (All of these tools can be downloaded from here)



use strict;

my $mqueue_directory = "/var/spool/mqueue";
my %occurrences;

use File::Find;

# Recursively find all files and directories in $mqueue_directory
find( \&wanted, $mqueue_directory );

sub wanted {

    # Is this a qf* file?
    if (/^qf\w{14}/) {
        open( QF_FILE, $_ );
        while () {

            # Lines beginning with R contain an envelope recipient
            if (/^R.*:<(.*)>$/) {
                my $domain = lc($1);

                # Add 1 to the %occurrences hash

# Subroutine to sort hash by ascending value
sub hashValueAscendingNum {
    $occurrences{$a} <=> $occurrences{$b};

# Print sorted results
foreach my $key ( sort hashValueAscendingNum ( keys(%occurrences) ) ) {
    print "$occurrences{$key} $key\n";

This prints to screen the qty and full email address of messages in queue. Looking at the bottom few rows you will typically find your main source of mailq stress.

Read more

AS400 OS400 iSeries SNMP strings MRTG Graphs

AS400 performance graphing with MRTG can be a tricky thing. Once you have a public read only SNMP string defined and you have enabled SNMP on the iSeries you can test using snmpwalk from the linux server you plan on generating the MRTG graphs from.


This is an example snmpwalk command for an as400

snmpwalk -v 2c -c YOURSNMPSTRING

Once the snmpwalk returns the SNMP information we are ready to poll it with MRTG and make some graphs.  The as400 will OFTEN time out and not complete a full SNMP return. I don’t know why this is. This is with very large systems as small alike. This is not the post to teach MRTG, but this is the spot to find the strings and the math I used to generate the graphs for our AS400s. Below are the keys to generating the MRTG graphs for your AS400. CPU, Users, RAM, ASP and others..


For real MRTG code and examples,

Read more