I wrote this script for me :-)
It returns the time in seconds to the expiration.
(it does NOT check if the certificate is valid!)
Code:
#!/bin/sh
DATE="/bin/date"
OPENSSL="/usr/local/openssl/current/bin/openssl"
HOST=$1
PORT=$2
if [ "$HOST" == "" ]; then
exit
fi
if [ "$PORT" == "" ]; then
PORT="443"
fi
CMD=`echo "" | $OPENSSL s_client -connect $HOST:$PORT 2>/dev/null | $OPENSSL x509 -enddate -noout 2>/dev/null| sed 's/notAfter\=//'`
if [ "$CMD" != "" ]; then
EXPIRE_DATE=`$DATE -d "$CMD" +%s`
TIME=`$DATE +%s`
EXPIRE_TIME=`expr $EXPIRE_DATE - $TIME`
echo $EXPIRE_TIME
fi
(it does NOT check if the certificate is valid!)
Comment