Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a private postfix relay VPS which is used by customers where they've installed their own e-mail servers in their offices and hosted over their ADSL connection. In the interests of reliable e-mail delivery, it's really not recommended to send mail directly from ISP IP addresses so I offer them the ability to use our private relay. However one of these customers has decided to send a newsletter to 5,000 recipients. I caught this straight away and dumped them all into the hold queue.

But now I'd like to try and flush this queue in batches, starting with the oldest messages.

Anyone got any ideas how to do this?
It looks like it would be a monster of a shell script to grep through the output of postqueue -p

share|improve this question
up vote 3 down vote accepted

If you have an idea of how old the oldest message is, you could do it with some grep and awk magic. I.e., if the oldest message is from Fri Jul 13, you could do this:

postqueue -p |grep "Fri Jul 13"|head -5000 | awk '{print "postsuper -I", $1}'|sh

to take the first 5000 messages found for that date. This doesn't do any sorting on which time during that date the mail was sent, if you want that, you could just add the hour for each hour.

share|improve this answer
That's brilliant. I need to learn awk! – bbradley Jul 18 '12 at 9:42
To order using the "hour" field you can simply use sort -k6. E.G.: 'mailq | grep '^[A-Z0-9]' | grep 'Sun Oct 11' | sort -k6 -r' – Antonio Bardazzi Oct 11 '15 at 20:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.