Skip to content

Instantly share code, notes, and snippets.

@mrunderline
Created May 11, 2021 06:32
Show Gist options
  • Save mrunderline/82f6fa22e86c0fc307c793d701d701ba to your computer and use it in GitHub Desktop.
Save mrunderline/82f6fa22e86c0fc307c793d701d701ba to your computer and use it in GitHub Desktop.
#!/bin/bash
website="$1"
certificate_file=$(mktemp)
echo -n | openssl s_client -servername "$website" -connect "$website":443 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > $certificate_file
date=$(openssl x509 -in $certificate_file -enddate -noout | sed "s/.*=\(.*\)/\1/")
date_s=$(date -d "${date}" +%s)
now_s=$(date -d now +%s)
date_diff=$(( (date_s - now_s) / 86400 ))
echo "$website will expire in $date_diff days"
rm "$certificate_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment