SSL証明書の期限を確認する
こんな感じで確認できる。
$ sslexpire secure.nicovideo.jp
https://secure.nicovideo.jp SSL certificate expires after 39 days and 13 hours (2014/06/30 23:59:00 JST)
#!/bin/bash
#
# usage: $0 domain[:port] [alert days] [timeout]
# ex)
# $0 yahoo.com 365
#
server=${1//:*/}
port=${1/*:/}
test "$server" = "$port" && port=443
limit=${2-60} # default 60 days
timeout=${3-3} # default timeout 3 seconds
notafter=$(timeout $timeout openssl s_client -connect $server:$port < /dev/null 2> /dev/null | openssl x509 -enddate -noout 2> /dev/null | cut -d= -f2)
if [ "$notafter" ]; then
s=$(( $(date --date "$notafter" +%s) - $(date +%s) ))
if [ $limit -ge $((s / 86400)) ]; then
d=$(date --date "$notafter" +"%Y/%m/%d %H:%M:%S %Z")
days=$((s/86400))
hours=$((s%86400/3600))
echo -n "https://$server SSL certificate expires after "
if [ $days -gt 0 ]; then
echo -n $days day
if [ $days -gt 1 ]; then
echo -n s
fi
fi
if [ $hours -gt 0 ]; then
if [ $days -gt 0 ]; then
echo -n " and "
fi
echo -n $hours hour
if [ $hours -gt 1 ]; then
echo -n s
fi
fi
echo " ($d)"
exit 1
fi
else
echo "https://$server is not supported SSL or timeout?"
exit 1
fi
タイムアウトの処理はもうちょっとなんとかしたほうがいい。