Chinaunix首页 | 论坛 | 博客
  • 博客访问: 852339
  • 博文数量: 254
  • 博客积分: 5350
  • 博客等级: 大校
  • 技术积分: 2045
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-27 13:27
文章分类

全部博文(254)

文章存档

2015年(1)

2014年(9)

2013年(17)

2012年(30)

2011年(150)

2010年(17)

2009年(28)

2008年(2)

分类: LINUX

2010-04-22 12:03:22

postfix:删除队列中 from/to 某个地址的邮件(perl)

postfix:删除队列中 from/to 某个地址的邮件(perl)
 最简单的就是 : postsuper -d ALL
作为Postfix MTA的管理员postfix:删除队列中 <wbr>from/to <wbr>某个地址的邮件(perl),维护队列是家常便饭postfix:删除队列中 <wbr>from/to <wbr>某个地址的邮件(perl),但如何能够方便的按自己的意愿控制对列呢?这需要一点perl和regexp的知识。
  以下提供一个perl的小程序,由一个国外朋友写的,通过命令行postfix:删除队列中 <wbr>from/to <wbr>某个地址的邮件(perl)传递正则表达式postfix:删除队列中 <wbr>from/to <wbr>某个地址的邮件(perl),匹配的邮件将被删除。
  queue_mgr.pl
  #!/usr/bin/perl$REGEXP = shift || die "no email-adress given (regexp-style, e.g. bl.*\@yahoo.com)!";@data = qx-p; for (@data) { if (/^(\w+)\*?\s/) { $queue_id = $1; } if($queue_id) { if (/$REGEXP/i) { $Q{$queue_id} = 1; $queue_id = ""; } } } open(POSTSUPER,"| postsuper -d -") || die "couldn't open postsuper" ; foreach (keys %Q) { print POSTSUPER "$_\n"; }; close(POSTSUPER);
还有一种方法:
mailq | awk  {print $1}' | tr -d '*' | xargs -n 1 postsuper -d
  
 换成你要删除的email address.
  
  
以下是另外一个 脚本:
  
  
#!/usr/bin/perl -w # # pfdel - deletes message containing specified address from # Postfix queue. Matches either sender or recipient address. # # Usage: pfdel # use strict; # Change these paths if necessary. my $LISTQ = "/usr/sbin/postqueue -p"; my $POSTSUPER = "/usr/sbin/postsuper"; my $email_addr = ""; my $qid = ""; my $euid = $>; if ( @ARGV != 1 ) { die "Usage: pfdel \n"; } else { $email_addr = $ARGV[0]; } if ( $euid != 0 ) { die "You must be root to delete queue files.\n"; } open(QUEUE, "$LISTQ |") || die "Can't get pipe to $LISTQ: $!\n"; my $entry = ; # skip single header line $/ = ""; # Rest of queue entries print on # multiple lines. while ( $entry = ) { if ( $entry =~ / $email_addr$/m ) { ($qid) = split(/\s+/, $entry, 2); $qid =~ s/[\*\!]//; next unless ($qid); # # Execute postsuper -d with the queue id. # postsuper provides feedback when it deletes # messages. Let its output go through. # if ( system($POSTSUPER, "-d", $qid) != 0 ) { # If postsuper has a problem, bail. die "Error executing $POSTSUPER: error " . "code " . ($?/256) . "\n"; } } } close(QUEUE); if (! $qid ) { die "No messages with the address <$email_addr> " . "found in queue.\n"; } exit 0;
阅读(1425) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~