Last active
April 20, 2018 17:00
-
-
Save iddqd3/b80ed174cfda77c5cf9a4124e4b86185 to your computer and use it in GitHub Desktop.
Check end date SSL certificate (for letsencrypt)
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 | |
# Check end date certificate | |
# Using: script.sh example.net | |
DOMAIN=$1 | |
CERT_DOWNLOAD_PATH=/tmp | |
PORT=443 | |
ALERT_TIME=604800 # 7 days | |
CERT="$CERT_DOWNLOAD_PATH/$DOMAIN.pem" | |
if [ ! -f "$CERT" ]; then | |
openssl s_client -connect "$DOMAIN:$PORT" 1> "$CERT" 2>/dev/null | |
fi | |
if openssl x509 -checkend "$ALERT_TIME" -noout -in "$CERT"; then | |
echo "Valid - $(openssl x509 -noout -in $CERT -enddate)" | |
exit 0 | |
else | |
echo 'Need renew' | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment