how to check if a string is a valid mailq mailid using bash?

292 Views Asked by At

I am stuck.

I am wondering how to check if a Q-ID is a valid mailq ID.

/var/spool/mqueue (3 requests)
-----Q-ID----- --Size-- -----Q-Time----- ------------Sender/Recipient-----------
m9TMLQHG012749     1103 Thu Oct 30 11:21 <[email protected]>
                 (host map: lookup (electrictoolbox.com): deferred)
                                         <[email protected]>
m9TMLRB9012751    37113 Thu Oct 30 11:21 <[email protected]>
                 (host map: lookup (electrictoolbox.com): deferred)
                                         <[email protected]>
m9TMLPcg012747   240451 Thu Oct 30 11:21 <[email protected]>
                 (host map: lookup (electrictoolbox.com): deferred)
                                         <[email protected]>
                Total requests: 3

thanks for any hint.

1

There are 1 best solutions below

1
On BEST ANSWER

Based on your last comment, I guess this is what would suffice.

randomMailQId=XXXXXXXX # get this populated

if mailq | grep "^$randomMailQId\s"; then 
    echo Valid
else
    echo Invalid
fi