linuxbashmail-queue

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


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 <apache@localhost.localdomain>
                 (host map: lookup (electrictoolbox.com): deferred)
                                         <test@electrictoolbox.com>
m9TMLRB9012751    37113 Thu Oct 30 11:21 <apache@localhost.localdomain>
                 (host map: lookup (electrictoolbox.com): deferred)
                                         <test@electrictoolbox.com>
m9TMLPcg012747   240451 Thu Oct 30 11:21 <apache@localhost.localdomain>
                 (host map: lookup (electrictoolbox.com): deferred)
                                         <test@electrictoolbox.com>
                Total requests: 3

thanks for any hint.


Solution

  • 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