Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions scripts/devops-tools/ssl_expiry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,61 @@
# url: https://www.ssllabs.com/ssltest/

echo "=== SSL Expiry Checker ==="

read -p "Enter domain (e.g. google.com): " domain

if [ -z "$domain" ]; then
domain="google.com"
fi

echo "Connecting to $domain:443..."
echo ""

# Check if openssl is installed
if ! command -v openssl >/dev/null 2>&1; then
echo "Error: openssl utility is not installed."
exit 1
fi
res=$(echo | openssl s_client -servername "$domain" -connect "$domain":443 2>/dev/null | openssl x509 -noout -dates -issuer)
if [ -z "$res" ]; then

# Fetch certificate details
cert_info=$(echo | openssl s_client -servername "$domain" -connect "$domain:443" 2>/dev/null | openssl x509 -noout -dates -issuer)

# Verify certificate was retrieved
if [ -z "$cert_info" ]; then
echo "Failed to retrieve SSL certificate details."
else
echo "$res"
exit 1
fi

# Display certificate information
echo "$cert_info"
echo ""

# Extract expiry date
expiry_date=$(echo "$cert_info" | grep "notAfter" | cut -d= -f2)

# Convert expiry date to Unix timestamp
expiry_ts=$(date -d "$expiry_date" +%s 2>/dev/null)
current_ts=$(date +%s)

# Validate timestamp conversion
if [ -z "$expiry_ts" ]; then
echo "Unable to calculate certificate expiry."
exit 1
fi

# Calculate remaining days
days_left=$(( (expiry_ts - current_ts) / 86400 ))

echo "Days Remaining: $days_left"
echo ""

# Display certificate health status
if [ "$days_left" -lt 0 ]; then
echo "❌ EXPIRED: Certificate has already expired!"
elif [ "$days_left" -le 7 ]; then
echo "🚨 CRITICAL: Certificate expires within 7 days!"
elif [ "$days_left" -le 30 ]; then
echo "⚠ WARNING: Certificate expires within 30 days!"
else
echo "✅ HEALTHY: Certificate is valid."
fi