Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: hashing out lines from mailq...

by gellyfish (Monsignor)
on May 24, 2006 at 07:39 UTC ( #551292=note: print w/replies, xml ) Need Help??

in reply to hashing out lines from mailq...

This is a dumb brute-force parser for the output of mailq. If you just want to get the messages from MAILER-DAEMON you can check $entry->{from} when you are iterating over @entries:

my $header = 1; my @entries; my $entry = {}; while(<>) { if ($header) { $header = 0 if /^--/; next; } if (/^(\S+)\s+(\d+)\s+(.+?)\s+<?(\S+)>?/) { push @entries, $entry if exists $entry->{msg_id}; $entry = {}; $entry->{msg_id} = $1; $entry->{size} = $2; $msg->{date} = $3; $msg->{from} = $4; } elsif (/\s+\((.*)\)/) { $entry->{message} = $1; } elsif ( /\s+<(.*)>?/ ) { $entry->{recipients} = [] unless exists $entry->{recipients}; push @{$entry->{recipients}}, $1; } } push @entries, $entry if exists $entry->{msg_id}; foreach $entry ( @entries ) { print $entry->{msg_id}, join " ", @{$entry->{recipients}},"\n"; }


Replies are listed 'Best First'.
Re^2: hashing out lines from mailq...
by perlknight (Pilgrim) on May 24, 2006 at 14:54 UTC
    Thanks. How would I go about geting the following for all deferred messages: qid, from, all recipients? Is there a better way of doing this besides parsing the output of mailq with regex? Thanks.

      That code does it, you just have to look for 'Defered' in $entry->{message}. The only other alternative (for sendmail at least) is to parse all of the 'q' files in /var/spool/mqueue, which will almost certainly by more of a pain.


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://551292]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2023-06-08 19:31 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (35 votes). Check out past polls.