sendmail mailq sort by year regular expression, updated naming convention

239 views Asked by At

Following up on this suggestion for a mailq sort, in our case we'd like to add the year in the sort, as this is a quarantine. How would you include the first character in the first column, which is the year? The first 0 from 001CJwkY1702541 is 2020.

mailq -qQ|grep "^[A-F0-9]" | sort -k8n -k4M -k5n -k6n
001CJwkY1702541 5623 Wed Jan  1 07:19 <[email protected]>

Also from the sendmail 8.11 docs, page 79:

All queue files have the name x fYMDhmsNPPPPP where YMDhmsNPPPPP is the id for this message and the x is a type. The individual letters in the id are:
Y Encoded year
M Encoded month
D Encoded day
h Encoded hour
m Encoded minute
s Encoded second
N Envelope number
PPPPP At least five digits of the process ID

This appears to be old as 001CJwkY1702541 does not correspond to fYMDhmsNPPPPP. Is there an updated document that shows this? The first number, "0" is the year and the second number, also a "0", appears to be January, and the third number, "1", is the day of the month. But that doesn't always make sense, e.g., with another quarantined queue id such as 00ACF2XJ4027295.

1

There are 1 answers

1
RobbieTheK On

My colleague came up with this. To sort by the initial digit but not the rest of that string, you would need to split it off from the rest. That will renumber the remaining fields.

mailq -qQ | sed -e 's/^\(.\)/\1 /' | grep "^[A-F0-9]" | sort -k1n -k5M -k6n -k7n|less

This puts it in incrementing order. I'll see if I can get the most recent to be first and update here accordingly but this essentially answers my question.