You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

delete-mailq-by-domain.pl 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Getopt::Long;
  5. $ENV{'PATH'} = "/sbin:/bin:/usr/sbin:/usr/bin";
  6. my ($domain);
  7. my $list = 0;
  8. (help()) if (!$ARGV[0]);
  9. GetOptions ('l' => \$list, 'd=s' => \$domain) or (help());
  10. (list_queue()) if ($list == 1);
  11. (delete_queue()) if ($domain);
  12. sub delete_queue {
  13. my $ids = `postqueue -p`;
  14. my @ids = split /\n/, $ids;
  15. for my $id (@ids) {
  16. next if $id =~ /^[\s\(-]/;
  17. chomp $id;
  18. next unless $id;
  19. $id =~ s/(.*?)\**\s.*/$1/;
  20. #print "$id\n";
  21. my $match = `postcat -q $id | grep '$domain'`;
  22. next unless $match;
  23. #print "Deleting ID: $id\n";
  24. my $saida = `postsuper -d $id`;
  25. print $saida;
  26. }
  27. }
  28. sub list_queue {
  29. my %hash_mail = ();
  30. my @queue = `postqueue -p`;
  31. my($queue,$key,$total);
  32. foreach $queue(@queue) {
  33. chomp $queue;
  34. if ( $queue =~ /^\s+.*\@(.*)/ ) {
  35. $hash_mail{$1}++;
  36. }
  37. }
  38. print"\nTOTAL\tTO\n";
  39. print"-----
  40. ----------------------------------------------------------------\n";
  41. foreach $key (reverse sort { $hash_mail{$a} <=> $hash_mail{$b}} keys
  42. %hash_mail) {
  43. $total += $hash_mail{$key};
  44. print"$hash_mail{$key} - $key\n";
  45. }
  46. print"\n$total -> TOTAL QUEUE\n";
  47. }
  48. sub help {
  49. print "Usage $0 -l To list a row of E-mail
  50. Usage $0 -d domain.com To delete the mensgens the Domain\n";
  51. }