Mailq regex match

Hi,

# mailq | awk '{match($0, /quota/)} {print $0}'  | head
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------

9A6A7DE117E    84309 Sat Sep 30 14:14:50  alerts-noreply+xxxxx=xxx.sg@xxx.xx.xxx
(host alt1.gmail-smtp-in.l.google.com[x.x.x.x] said: 452-4.2.2 The email account that you tried to reach is over quota. Please direct 452-4.2.2 the recipient to 452 4.2.2  https://support.google.com/mail/?p=OverQuotaTemp w3si1206275ywl.503 - gsmtp (in reply to RCPT TO command))
                                         reitest@gmail.com

I am trying to get to print "9A6A7DE117E" "reitest@gmail.com"

Appreciate your advise.. Thanks!

      BEGIN {err=0}
      mailq | awk ' /alerts/ {q_id=$1; next}
                   /quota/  {err=1;next }
                   (err==1) { print q_id, $(NF); err=0}'

Try that - what you need is to remember the queue id and then print it when you get the quota error, along with the last field on the last line of the message - email.

You can parse that last field however you want - I do not know if it is constant or not. Note: I assumed the lines I see in your example are indeed newlines. Not some weirdness line wrapping.

1 Like

Here is something based on assumptions:-

mailq | awk '/^[^ ]/&&!/^\(/{q_id=$1;next}NF&&!/^\(/{print q_id, $1}'
1 Like