Hi Folks,
The problem I've solved below may have bugged you too, so I'm
sharing the solution.
To set the scene: Probably like many of you, I do my email work
"off-line" and then, when there is mail to be sent, I dial up to
the ISP and send the mail (basically using "sendmail -q").
However, I've been bugged for ages by the fact that sendmail can
lock some or all of the mail-queue files (as shown by asterisks when
'mailq' is run) for many minutes, which can block the queue for ages.
My usual solution is simply to sit around until 'mailq' shows no
asterisks, and then dial out and send, but I've also tried other, more
drastic, approaches which have their disadvanrages.
Yesterday, however, I got an idea (could have seen it years ago).
What process is locking the queue?
No doubt sendmail itself. So I did a 'ps -aux | grep sendmail' while
the queue was locked. And there is was.
First, check whether the queue is locked:
# mailq
Mail Queue (1 request)
--Q-ID-- --Size-- -----Q-Time-----
------------Sender/Recipient------------
VAA00979* 16895 Tue Jun 3 21:09 efh
(host map: lookup (<destination domain>): deferred)
<list of recipient addresses here>
So there it is locked (see "*"). Now check for what sendmail is up to:
# ps -aux | grep sendmail
root 160 0.0 1.1 1256 720 ? S May 23 0:00 sendmail: accepting
root 1027 0.0 1.4 1336 940 ? S 21:11 0:00 sendmail: VAA00979:
And there is sendmail working on "VAA00979", with process ID 1027.
So now stop it:
# kill -15 1027
And now see what has heppened:
# mailq
Mail Queue (1 request)
--Q-ID-- --Size-- -----Q-Time-----
------------Sender/Recipient------------
VAA00979 16895 Tue Jun 3 21:09 efh
(host map: lookup (<destination domain>): deferred)
<etc>
and there is it unlocked! Short, sweet, snappy and instantaneous.
What I did above could very easily be implemented in a suitable script
for sending mail as a batch job when dialling out, which I intend to do.
So the "algorithm" is:
Run 'mailq' and grep for any "*"
If found, extract message identifiers (e.g. "VAA00979" from "VAA00979*")
run 'ps -aux' and match on "sendmail: <identifier>", and extract its PID
kill -15 PID
Lines 3, 4 and 5 could be little 'awk' jobs, feeding the 'grep' output
from line 1 to 'awk'.
There it is.
Any comments?
Best wishes to all,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding)