Skip to content

Instantly share code, notes, and snippets.

@Na0ki
Last active March 7, 2020 01:58
Show Gist options
  • Save Na0ki/c8649ea86c8cf61f7fcde40ed2d36b03 to your computer and use it in GitHub Desktop.
Save Na0ki/c8649ea86c8cf61f7fcde40ed2d36b03 to your computer and use it in GitHub Desktop.
指定したドメイン名の証明書期限(notAfter)までの残日数を返すだけのやつ
#!/bin/bash
set -ue
targets=("example.com")
targets_metric_name=("ex")
now=$(date "+%s")
function remaining() {
local expiresAt=$(echo | openssl s_client -connect $1:443 2>&1 | openssl x509 -dates -noout|grep notAfter|sed -e 's/notAfter=//g'| xargs -i date -d "{}" "+%s")
if [ $2 -gt $expiresAt ]; then
echo -1
else
local diff=$(($expiresAt - $2))
local day=$((24 * 60 * 60))
echo $(($diff / $day))
fi
}
for ((i=0; i < ${#targets[@]}; ++i)); do
metric=$(remaining ${targets[$i]} $now)
echo -e "ssl_expires_in.${targets_metric_name[$i]}\t$metric\t$now"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment