Created
April 22, 2025 15:30
-
-
Save rjchicago/b32c7abf55f90bb02a28f84dfaea3c3c to your computer and use it in GitHub Desktop.
Check the SSL expiration for a given site using openssl..
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 characters
| check_ssl_expiry() { | |
| local SERVER="$1" | |
| if [[ -z "$SERVER" ]]; then | |
| echo "Usage: check_ssl_expiry <server>" | |
| return 1 | |
| fi | |
| local EXPIRY_DATE | |
| EXPIRY_DATE=$(echo | openssl s_client -servername "$SERVER" -connect "$SERVER:443" 2>/dev/null \ | |
| | openssl x509 -noout -enddate \ | |
| | cut -d= -f2) | |
| if [[ -n "$EXPIRY_DATE" ]]; then | |
| echo "SSL certificate for $SERVER expires on: $EXPIRY_DATE" | |
| else | |
| echo "Failed to retrieve certificate for $SERVER" | |
| return 2 | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment