Created
May 7, 2013 18:42
-
-
Save mrpatrick/5535035 to your computer and use it in GitHub Desktop.
Print how many days left until an SSL certificate file expires. Usage: ssl_expire_days CERTFILE
This file contains hidden or 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 | |
ssl_expire_days() { | |
# Show usage info if not called with a certificate file | |
if [ $# -eq 0 ]; then | |
echo "Usage: ssl_expire_days CERTFILE" | |
return 0 | |
fi | |
cert=$1 | |
cert_expire_date=$(openssl x509 -noout -in ${cert} -enddate | sed 's/^[a-zA-Z]*=//g') | |
expires_in_days=$(( ($(date -d "${cert_expire_date}" +%s) - $(date +%s)) / 86400)) | |
echo ${expires_in_days} | |
} | |
ssl_expire_days $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Take a look at https://gist.github.com/simonwhitaker/4179149 if your looking to check the expire date of a domain instead of a file