Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: hashing out lines from mailq...

by gellyfish (Monsignor)
on May 24, 2006 at 07:39 UTC ( [id://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"; }

/J\

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.

      /J\

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-25 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found