I'm writing a bash script to search the contents of a postfix log. The results are stored in a variable called "results". To keep the script's output readable (since this variable contains multiple lines from the log) I am setting the IFS variable to an empty string so that the line breaks in my grep results are preserved.
The result set that I wish to search will look like this:
Code:
Jul 3 23:12:14 mf04 postfix-mxmf/qmgr[6250]: CCB2825AE1C: from=<test@test.com>, size=2546, nrcpt=2 (queue active)
Jul 3 23:12:14 mf04 postfix-mxmf/smtp[31012]: CCB2825AE1C: to=<user1@domain.com>, relay=some.server.address[192.168.30.201]:25, delay=8.2, delays=8.1/0.01/0/0.02, dsn=2.0.0, status=sent (250 low[1484])
Jul 3 23:12:14 mf04 postfix-mxmf/smtp[31012]: CCB2825AE1C: to=<user2@domain.com>, orig_to=<user1@domain.com>, relay=some.server.address[192.168.30.201]:25, delay=8.2, delays=8.1/0.01/0/0.02, dsn=2.0.0, status=sent (250 low[1484])
Jul 3 23:12:14 mf04 postfix-mxmf/qmgr[6250]: CCB2825AE1C: removed
I want to take these results and filter out the lines with "postfix-mxmf/smtp" and just process those. For each line, I want to grab the email address and the "low[somenumber]". Both of these I can do with regexes, that's no problem. It's processing the output line by line that I'm having trouble with.
The end result I want is that, for each "postfix-mxmf/smtp" line, I grep a different logfile for the email address and "low[somenumber]" and return a line that shows that the message was delivered, like so:
Code:
Jul 3 23:11:39 drd00 bingo[22660]: rfc2821: low[1484]: to=<user1@domain.com>, delay=0, status=sent
Jul 3 23:11:39 drd00 bingo[22660]: rfc2821: low[1484]: to=<user2@domain.com>, delay=0, status=sent
Any ideas?