How to purge files from /var/spool/mqueue in a clean way?

Extracted from comp.mail.sendmail
Tip provided by Richard Hernandez
: Anybody know of a way to purge files from the /var/spool/mqueue directory
: with Sendmail 8.8.5 in a clean way (without just doing an 'rm')? Sendmail is
: consuming 60% or so of the CPU after a box crash, and it looks like there
: are an abnormall number of files in the mentioned directory. Thanks.

Simple method is to stop sendmail, rename the mqueue directory,
create a new mqueue directory, and requeue the mail in the old
directory.

#!/bin/sh
# Requeue mail multiple instances as the load permits


if [ -d "$1" ]
then
        /usr/lib/sendmail -OQueueDirectory=$1 -OTimeout.queuereturn=99d -q &
else
        echo "Usage: reque <directoryname>"
fi


For possibly bad files in the directory, this script is more or
less from the sendmail book. Remove bad files, renames, orphan
files, etc. Use at your own risk.

#!/bin/sh

#/etc/init.d/sendmail stop
cd /usr/spool/que/que2
#remove zero length qf files
for qf in qf*
do
    if [ -r $qf ]
    then
        if [ ! -s $qf ]
        then
            echo -n ""
            rm -f $qf
        fi
    fi
done

#rename tf files to be qf if the qf file does not exist
for TF in `ls tf*`
do
    qf=`echo "$TF" | sed 's/t/q/'`
    if [ -r $TF -a ! -f $qf ]
    then
        echo -n ""
        mv $TF $qf
    else
        if [ -f $TF ]
        then
            echo -n ""
            rm -f $TF
        fi
    fi
done

# remove df files with no corresponding qf files
for df in df*
do
    qf=`echo $df | sed 's/d/q/'`
    if [ -r $df -a ! -f $qf ]
    then
        echo -n ""
        mv $df `echo $df | sed 's/d/D/'`
    fi
done

#announce files that have bewen saved suring disaster recovery
for xf in [A-Z]f*
do
    if [ -f $xf ]
    then
        echo -n ""
    fi
done

#/etc/init.d/sendmail start


Follow-up :
| Previous | Next | Index of category | Main Index | Submit |


Appears in section(s) : email daemon
Tip recorded : 30-11-1998 21:58:14
HTML page last changed : 27-07-1999 20:09:54