Skip to content

Instantly share code, notes, and snippets.

@iddqd3
Last active April 20, 2018 17:00
Show Gist options
  • Save iddqd3/b80ed174cfda77c5cf9a4124e4b86185 to your computer and use it in GitHub Desktop.
Save iddqd3/b80ed174cfda77c5cf9a4124e4b86185 to your computer and use it in GitHub Desktop.
Check end date SSL certificate (for letsencrypt)
#!/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