2012-04-05 121 views
1

我想用下面的命令:使用OpenSSL讀取多個證書

openssl x509 -noout -in /etc/pki/tls/certs/cert1.pem -enddate 
openssl x509 -noout -in /etc/pki/tls/certs/cert2.pem -enddate 
openssl x509 -noout -in /etc/pki/tls/certs/certN.pem -enddate 

有沒有辦法讀取使用通配符的所有證書?例如,

openssl x509 -noout -in /etc/pki/tls/certs/*.pem -enddate 

任何幫助將不勝感激。先謝謝你。

+0

我已經設法使用一個文件名數組遍歷for循環。如果有更好的工作,請分享。謝謝 – Zeeshan 2012-04-05 15:51:01

回答

1

使用shell小腳本:

#! /bin/sh 

for file in /etc/pki/tls/certs/*.pem; do 
    echo -n "$file: " 
    openssl x509 -noout -in "$file" -enddate 
done 

把這個在一個文件,說certexpires.sh那麼你就可以運行它:

sh certexpires.sh 
0

我創造了我的終端別名和運行這個上整個文件夾中的文件(你可以調整它只在pem分機上運行,​​但這是我的改編)

alias ssl-opemu='_(){ for i in *; do openssl x509 -in $i -noout -text; done; }; _' 

我幾乎可以肯定,我從前一個線程繼承了這一點,所以對其原始所有者擁有所有權利。 :)

1

我對你的情況回答是這樣的命令:

ls /etc/pki/tls/certs/cert*.pem | xargs -L1 openssl x509 -noout -enddate -in 

說明

在第一步中,我把我的證件,我想分析的列表。例如在我的情況下,它可能是這樣的:

[[email protected] certs]# ls -1 */*.crt 
ewsport.org/ewsport.org.crt 
hxpro.cz/hxpro.crt 
jaguars.cz/jaguars.crt 
koudelka.photography/koudelka.photography.crt 
unicycle-hockey.cz/unicycle-hockey.cz.crt 
unipragga.cz/unipragga.cz.crt 

下一步,我想要從他們每個人獲得到期日期。

[[email protected] certs]# openssl x509 -noout -enddate -in hxpro.cz/hxpro.crt 
notAfter=Apr 24 11:29:21 2017 GMT 

現在我可以使用xargs將第一條命令的輸出發送到第二條命令。

[[email protected] certs]# ls -1 */*.crt | xargs -L1 openssl x509 -noout -enddate -in 
notAfter=Mar 31 15:08:20 2017 GMT 
notAfter=Apr 24 11:29:21 2017 GMT 
notAfter=Mar 23 21:23:42 2017 GMT 
notAfter=Apr 24 11:50:32 2017 GMT 
notAfter=Dec 11 16:32:41 2016 GMT 
notAfter=Mar 20 19:44:17 2017 GMT 

我使用了選項-L1,因爲openssl命令只需要一個-in文件作爲輸入。

+1

感謝您的回答。你能否提供一些解釋,說明爲什麼你發佈的命令解決了OP的問題 - 爲什麼它可能比已經提供的答案更好? – Tom 2017-02-01 12:48:38

+0

我想,我的解決方案更簡單,更清晰。 – 2017-02-02 09:15:22

+0

是的,但是...爲什麼?什麼'| xargs'嗎?或'-L1'? – Tom 2017-02-02 09:17:18

相關問題