大网数据广告活动
服务器运维问答

How can I delete all messages from a certain address from the mailqueue?

· 52CE 我爱测

We have a lot of messages in the mail queue from a certain address. I want to delete the lot of them. I've found ways to delete by subject line, but I want to search by From address, and that seems to be a lot trickier. (Note: th…

问题原文

原帖链接 · TRiG · CC BY-SA 3.0

We have a lot of messages in the mail queue from a certain address. I want to delete the lot of them. I've found ways to delete by subject line, but I want to search by From address, and that seems to be a lot trickier. (Note: these are mainly outgoing messages.)

Some Googling has found me this command on HowToForge, but there's no explanation of what it does.

postqueue -p | tail -n +2 | awk 'BEGIN { RS = "" } / spammer@example\.net/ { print $1 }' | tr -d '*!' | postsuper -d - 

I was trying to use mailqueuemng, but didn't get very far (it doesn't have a --help, for one thing).

已采纳解答

原帖链接 · Dan Pritts · CC BY-SA 4.0

The pipeline can be analyzed step by step to see what it does. Try running each command in sequence until you understand them all:

postqueue -p

print the queue

postqueue -p | tail -n +2 

get rid of the first couple lines

postqueue -p | tail -n +2 | awk 'BEGIN { RS = "" } / spammer@example\.net/ { print $1 }' 

search for any lines with [email omitted]; print the first field of those lines.

postqueue -p | tail -n +2 | awk 'BEGIN { RS = "" } / spammer@example\.net/ { print $1 }' | tr -d '*!'

get rid of any *!

This will output a bunch of queue ids.

postqueue -p | tail -n +2 | awk 'BEGIN { RS = "" } / spammer@example\.net/ { print $1 }' | tr -d '*!' | postsuper -d -

The final command tells postfix to delete those queue ids.

Read The Fine Man pages on postqueue, tail, tr, and postsuper. Awk is a more complicated, it's its own little language. you'll need a bit more than a man page to understand its complexity, although in my experience 99% of the awk usage is much like that particular one-liner.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-07-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。