Skip to content

Instantly share code, notes, and snippets.

@ckressibucher
Created December 21, 2019 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckressibucher/064847d55a481965d98484de64bc6364 to your computer and use it in GitHub Desktop.
Save ckressibucher/064847d55a481965d98484de64bc6364 to your computer and use it in GitHub Desktop.
check expiration date of TLS certificate
#!/bin/bash
hostname=$1
expire_str=$(true | openssl s_client -connect $hostname:443 2>/dev/null | openssl x509 -noout -enddate | cut -d = -f2)
expire=$(date -d "$expire_str" +%s)
current=$(date +%s)
secs_left=$(expr $expire - $current)
days_left=$(expr $secs_left / 3600 / 24)
echo $hostname exires at $expire_str "(this is in $secs_left seconds, ~ $days_left days)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment