Skip to content

Instantly share code, notes, and snippets.

@simonwhitaker
Created November 30, 2012 22:27
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonwhitaker/4179149 to your computer and use it in GitHub Desktop.
Save simonwhitaker/4179149 to your computer and use it in GitHub Desktop.
Get the expiry date of a secure website's SSL certificate at the command line
#!/bin/sh
ssl_expiry() {
# Show usage info if not called with a hostname
if [ $# -eq 0 ]; then
echo "Usage: ssl_expiry HOSTNAME"
return 0
fi
domain=$1
output=$(echo | openssl s_client -connect ${domain}:443 2>/dev/null | openssl x509 -enddate -noout)
# Output will look something like 'notAfter=May 10 23:59:59 2014 GMT'
# Split on = to remove the 'notAfter=' portion
end_date=${output##*=}
echo $domain $end_date
}
ssl_expiry $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment