【问题标题】:find all certificate files in any centos directory using the expiry date filter使用到期日期过滤器在任何 centos 目录中查找所有证书文件
【发布时间】:2021-04-07 23:18:42
【问题描述】:

拜托,我需要在 centos 盒子的任何目录中找到所有证书文件。

我用“exec”命令和 grep “not after”尝试了“find”。这仅显示证书的到期日期,但我也需要找到实际文件:

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

什么命令也可以列出证书文件及其到期日期的内容?

【问题讨论】:

    标签: linux shell awk grep certificate


    【解决方案1】:

    带有辅助脚本的版本:

    cat /root/expiry.sh

    #!/bin/bash
    name=$1
    expiry=$(openssl x509 -in $name -noout -text 2>/dev/null | grep -i "not after")
    if [[  $PIPESTATUS -eq 0 ]]; then
        echo -e "${name}\t${expiry}"
    fi
    

    像这样执行:

    find /etc/  -type f -exec /root/expiry.sh "{}" \;
    /etc/ssl/certs/ssl-cert-snakeoil.pem                Not After : Mar 30 22:59:59 2027 GMT
    /etc/ssl/certs/ca-certificates.crt              Not After : Dec 31 09:37:37 2030 GMT
    

    【讨论】:

    • 很高兴您喜欢这种方法。 :)
    • 那行得通。感谢您的帮助丁克。真的很抱歉,回来有点晚了
    【解决方案2】:

    你可以使用这个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)
    

    【讨论】:

    • 感谢您的帮助。真的很抱歉,回来晚了一点,但我无法运行该脚本。我将它作为脚本直接从 shell 运行,但无法让它工作
    猜你喜欢
    • 2018-08-06
    • 2013-01-15
    • 1970-01-01
    • 2012-03-29
    • 1970-01-01
    • 2016-07-26
    • 1970-01-01
    • 2015-04-07
    • 2016-07-15
    相关资源
    最近更新 更多