2 # $Cambridge: exim/src/src/exiqgrep.src,v 1.1 2004/10/07 10:39:01 ph10 Exp $
4 # Utility for searching and displaying queue information.
5 # Written by Matt Hubbard 15 August 2002
7 # Except when they appear in comments, the following placeholders in this
8 # source are replaced when it is turned into a runnable script:
16 # Routine for extracting the UTC timestamp from message ID
17 # lifted from eximstat utility
24 # Have this variable point to your exim binary.
25 my $exim = 'BIN_DIRECTORY/exim';
32 (0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, # 0-9
33 0,10,11,12,13,14,15,16,17,18,19,20, # A-K
34 21,22,23,24,25,26,27,28,29,30,31,32, # L-W
35 33,34,35, 0, 0, 0, 0, 0, # X-Z
36 0,36,37,38,39,40,41,42,43,44,45,46, # a-k
37 47,48,49,50,51,52,53,54,55,56,57,58, # l-w
41 if ($^O eq 'darwin') { # aka MacOS X
47 getopts('hf:r:y:o:s:zxlibRc',\%opt);
48 if ($opt{h}) { &help; exit;}
50 # Read message queue output into hash
52 # Identify which messages match selection criteria
54 # Print matching data according to display option.
61 Exim message queue display utility.
66 -f <regexp> Match sender address sender (field is "< >" wrapped)
67 -r <regexp> Match recipient address
68 -s <regexp> Match against the size field from long output
69 -y <seconds> Message younger than
70 -o <seconds> Message older than
71 -z Frozen messages only (exclude non-frozen)
72 -x Non-frozen messages only (exclude frozen)
74 [ NB: for regexps, provided string sits in /<string>/ ]
77 -c Display match count
78 -l Long Format [Default]
86 open(QUEUE,"$exim $eargs |") or die("Error openning pipe: $!\n");
90 #Should be 1st line of record, if not error.
91 if ($line =~ /^\s*(\w+)\s+(\S+)\s+(\w{6}-\w{6}-\w{2})\s+(<.*?>)/) {
96 $id{$msg}{birth} = &msg_utc($msg);
97 $id{$msg}{ages} = time - $id{$msg}{birth};
98 if ($line =~ /\*\*\* frozen \*\*\*$/) {
99 $id{$msg}{frozen} = 1;
101 $id{$msg}{frozen} = 0;
103 while(<QUEUE> =~ /\s+(.*?\@.*)$/) {
104 push(@{$id{$msg}{rcpt}},$1);
106 # Increment message counter.
109 print STDERR "Line mismatch: $line\n"; exit 1;
112 close(QUEUE) or die("Error closing pipe: $!\n");
116 foreach my $msg (keys(%id)) {
118 # Match sender address
119 next unless ($id{$msg}{from} =~ /$opt{f}/);
122 # Match any recipient address
124 foreach my $rcpt (@{$id{$msg}{rcpt}}) {
125 $match++ if ($rcpt =~ /$opt{r}/);
127 next unless ($match);
130 # Match against the size string.
131 next unless ($id{$msg}{size} =~ /$opt{s}/);
135 next unless ($id{$msg}{ages} < $opt{y});
139 next unless ($id{$msg}{ages} > $opt{o});
143 next unless ($id{$msg}{frozen});
147 next if ($id{$msg}{frozen});
149 # Here's what we do to select the record.
150 # Should only get this far if the message passed all of
153 # Increment match counter.
160 printf("%d matches out of %d messages\n",$mcount,$count);
163 foreach my $msg (sort { $opt{R} ? $id{$b}{birth} <=> $id{$a}{birth} : $id{$a}{birth} <=> $id{$b}{birth} } keys(%id) ) {
164 if (exists($id{$msg}{d})) {
170 printf("%s From: %s To: %s\n",$msg,$id{$msg}{from},join(';',@{$id{$msg}{rcpt}}))
172 # Otherwise Long format attempted duplication of original format.
173 printf("%3s %5s %s %s%s\n",$id{$msg}{age},$id{$msg}{size},$msg,$id{$msg}{from},$id{$msg}{frozen} ? " *** frozen ***" : "");
174 foreach my $rcpt (@{$id{$msg}{rcpt}}) {
175 printf(" %s\n",$rcpt);
184 foreach my $msg (keys(%id)) {
185 print "$id{$msg}{birth} $msg\tAge: $id{$msg}{age}\tSize: $id{$msg}{size}\tFrom: $id{$msg}{from}\tTo: " . join(" ",@{$id{$msg}{rcpt}}). "\n";
190 my $id = substr((pop @_), 0, 6);
192 my @c = split(//, $id);
193 while($#c >= 0) { $s = $s * $base + $tab62[ord(shift @c) - ord('0')] }