Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
530 views
in Technique[技术] by (71.8m points)

linux - find all certificate files in any centos directory using the expiry date filter

Please, I need to find all certificate files in any directory in the centos box.

I tried the "find" with "exec" command and grep "not after". This display only the expiry dates of the certificates but I need to find the actual files too:

find /etc/  -type f -exec openssl x509 -in {} -noout -text ; |
grep -i  "not after"

what command could list the cert files with the content of their expiry dates too?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You may use this find + awk:

while IFS= read -rd '' cert; do
   printf '%s :: ' "$cert"
   openssl x509 -in "$cert" -noout -text |
   awk -F ' *Not After : ' 'NF == 2 {print $2; exit}'
done < <(find /etc -type f -print0)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...