Skip to content

Instantly share code, notes, and snippets.

@mrpatrick
Created May 7, 2013 18:42
Show Gist options
  • Save mrpatrick/5535035 to your computer and use it in GitHub Desktop.
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
#!/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
@mrpatrick
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment