#!/bin/sh openssl=/usr/bin/openssl sed=/usr/bin/sed date=/bin/date echo=/bin/echo bc=/usr/bin/bc host=$1 port=$2 end_date=`$openssl s_client -connect $host:$port -servername $host -showcerts \ /dev/null | $openssl x509 -dates -noout 2>/dev/null | \ $sed -n 's/notAfter=//p'` if [ -n "$end_date" ] then end_date_seconds=`$date -j -f "%b %d %T %Y %Z" "$end_date" "+%s"` now_seconds=`$date '+%s'` $echo "($end_date_seconds-$now_seconds)/24/3600" | $bc fi exit 0