Last active
October 3, 2019 08:32
-
-
Save askin/d5efb7f37b61520a4fc87dd0dcd132f9 to your computer and use it in GitHub Desktop.
Revisions
-
askin revised this gist
Oct 3, 2019 . No changes.There are no files selected for viewing
-
askin created this gist
Oct 2, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ #!/bin/bash # Simple SSL cert days-till-expiry check script # by Askin Ozgur https://blog.yollu.com [email protected] # Derived from Glen Scott, www.glenscott.net PORT=443 if [ ${#} == 2 ]; then DOMAIN=$1 PORT=$2 elif [ ${#} == 1 ]; then DOMAIN=$1 else echo "Usage: $0 example.tld [port]" exit 1 fi # Check port is valid? if ! [[ ${PORT} == +([0-9]) ]]; then echo "Port must be numeric!!!" exit 1 fi openssl_output=$(echo " GET / HTTP/1.0 EOT" \ | openssl s_client -connect ${DOMAIN}:${PORT} -servername ${DOMAIN} 2>&1); if [[ "$openssl_output" = *"-----BEGIN CERTIFICATE-----"* ]]; then cert_expiry_date=$(echo "$openssl_output" \ | sed -n '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p' \ | openssl x509 -enddate \ | awk -F= ' /notAfter/ { printf("%s\n",$NF); } '); seconds_until_expiry=$(echo "$(date --date="$cert_expiry_date" +%s) - $(date +%s)" |bc); days_until_expiry=$(echo "$seconds_until_expiry/(60*60*24)" |bc); echo "$days_until_expiry"; else echo "NOT_FOUND"; fi exit 1