Created
September 1, 2024 07:33
-
-
Save doublemarket/268ece51ddf28538658f2bbb48a51ff1 to your computer and use it in GitHub Desktop.
SSL certificate expiration check script
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/bash | |
# ./certcheck.sh [domain name] | |
DOMAIN=$1 | |
notAfter=$(echo -n Q | openssl s_client -connect ${DOMAIN}:443 -servername ${DOMAIN} 2>/dev/null | openssl x509 -noout -enddate | grep notAfter | sed 's/notAfter=//') | |
notAfterEpic=$(date -d "${notAfter}" +\%s) | |
twoWeeksLaterEpic=$(date -d 'now + 2 weeks' +\%s) | |
nowEpic=$(date +\%s) | |
echo "now = "$(date) | |
echo "expiry = "$(date -d @${notAfterEpic}) | |
if [ $notAfterEpic -le $nowEpic ]; then | |
echo "The SSL cert for ${DOMAIN} has expired." | |
exit 1 | |
elif [ $notAfterEpic -le $twoWeeksLaterEpic ]; then | |
echo "The SSL cert for ${DOMAIN} will expire in two weeks." | |
exit 1 | |
else | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment