Created
April 26, 2022 07:28
-
-
Save teopost/e635a801dc87de43e184b5a6540ad0a6 to your computer and use it in GitHub Desktop.
zext_ssl_expiry.sh - check for expired certificates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
SERVER=$1 | |
TIMEOUT=5 | |
RETVAL=0 | |
SNI=$3 | |
TIMESTAMP=`echo | date` | |
if [ -z "$2" ]; then | |
PORT=443; | |
else | |
PORT=$2; | |
fi | |
EXPIRE_DATE=$(timeout $TIMEOUT bash -c "echo | openssl s_client -connect $SERVER:$PORT -servername $SNI 2>/dev/null | openssl x509 -noout -dates 2>/dev/null | grep notAf | |
ter | cut -d'=' -f2") | |
if [ $? -eq 124 ]; then | |
echo 365 | |
exit | |
fi | |
#EXPIRE_DATE=`(echo | openssl s_client -connect $SERVER:$PORT -servername $SNI 2>/dev/null | openssl x509 -noout -dates 2>/dev/null | grep notAfter | cut -d'=' -f2)` | |
EXPIRE_SECS=`date -d "${EXPIRE_DATE}" +%s` | |
EXPIRE_TIME=$(( ${EXPIRE_SECS} - `date +%s` )) | |
if test $EXPIRE_TIME -lt 0 | |
then | |
RETVAL=999 | |
else | |
RETVAL=$(( ${EXPIRE_TIME} / 24 / 3600 )) | |
fi | |
# debug | |
#echo "$(date): ${RETVAL}: $0 $@" >> /tmp/test.log | |
echo ${RETVAL} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment