#!/bin/sh echo=/bin/echo openssl=/usr/bin/openssl sed=/usr/bin/sed date=/bin/date bc=/usr/bin/bc host=$1 port=$2 end_date=`$echo "GET / HTTP/1.1" | $openssl s_client -host $host -port $port \ -starttls imap 2>/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