証明書の日付を自前で確認してなにがしの処理をする方法

いろいろ考えたんだけど、下記の感じでどうだろうか。

local diffUpdate=`openssl x509 -in /etc/letsencrypt/live/$1/fullchain.pem -noout -enddate | sed -e's/^[^=]*=//g' | xargs -I{} date --utc +"%s" --date="{}" | xargs -I{} echo "{}" "-" $(date --utc +"%s") |perl -e "print eval( <>);"`

if [ 24192000 -gt ${diffUpdate}0 ] ; then
echo "28日以内"
fi

最初にopenssl x509 で終了日付を取り、dateコマンドで、ctimeに変換した後、

本日日付のctime を取得して減算する数式を作り、perl で eval という感じ。

最後のif は 2419200が 28日の秒数表現で、最後に0を付加しているのは、diffUpdateが空文字でもこけないカラクリ。

 

以上