I am new to the world of scripting. My requirement is to write a bash script which will parse the output of ‘/usr/sbin/postqueue -p’ and get the mail queue count (highlighted number in the last line).
<Output of postqueue -p>
postqueue: warning: Mail system is down -- accessing queue directly
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
9F34D414BA0A 304 Wed Aug 3 11:50:01 <sender>
<recipient>
85F00414D434 304 Wed Aug 3 11:50:02 <sender>
<recipient>
0C5E2414D435 303 Wed Aug 3 11:50:03 <sender>
<recipient>
73C6041CCC47 304 Wed Aug 3 11:50:03 <sender>
<recipient>
-- 1 Kbytes in 4 Requests.
So, how do I use grep to do a multi-line search? When I searched online, I got to know about pcregrep but I didn’t get which package provides that binary. (I am using RHEL7). I skimmed through the man page of grep but couldn’t find anything interesting.
Second question is, how do I use regex in bash to extract that mail queue count from the last line?
I got it to work in Python but I want to get this done in bash because I will have to modify an existing script to use this logic.
Let me know if you have any thoughts, thanks.