
Originally Posted by
/bin/bash.org
I'm not entirely comfortable with the idea of a completely arbitrary queue deletion. I do agree that queue maintenance is necessary, however. Something that I do is create myself a couple of little scripts to help out, using the MTA's own management tools where possible. Here's one I use for exim (it's quick'n'dirty, so don't laugh - submit a patch

).
Code:
#!/bin/bash -
# remove_null_mail.sh
# Removes queued mail with a null ( <> ) recipient
mailq () {
exim -bp
}
for line in `mailq|grep '<>'|awk '{ print $3 }'`; do /usr/sbin/exim -Mrm $line; done
Basically, as chirpy said, figure out what's causing the problems and deal with that if possible. There is no way I would delete the entire queue automatically. I especially wouldn't delete the files directly while a native queue maintenance tool exists. As an aside, often the queue can be a good barometer of other issues, too (battsl1005@aol.com anyone?)...
You script is doing same elimination of entire exim mail que. However in case of huge spam attacks I prefer to disable exim and then clean que by direct files deletion.
Also in case of high server load it is preferable to use more simple ways to clean que with as less commands number as possible.
Btw, you can use this script which will delete all emails in que that older then 1 hour:
Code:
#!/bin/bash -
# remove_old_mail.sh
# Removes queued mail with messages older then one hour
mailq () {
exiqgrep -o 3600 -b
}
for line in `mailq| awk '{ print $1 }'`; do /usr/sbin/exim -Mrm $line; done
Or this script to delete all messages with a null ( <> ) sender
Code:
#!/bin/bash -
# remove_null_sender.sh
# Removes queued mail with a null ( <> ) sender
mailq () {
exiqgrep -b
}
for line in `mailq |awk '{print$1 " " $3}' | grep '<>' | awk '{print$1}'`; do /usr/sbin/exim -Mrm $line; done
Also you can see many useful exim options here:
http://www.exim.org/exim-html-4.50/d...l/spec_49.html