Write a script that checks SSL certificate expiry for a list of domains and warns under 30 days.

AdvancedHands-onBash scripting tasks
Answer
#!/usr/bin/env bash
set -euo pipefail
WARN_DAYS=30
while read -r domain; do
  end=$(echo | openssl s_client -servername "$domain" -connect "$domain:443" 2>/dev/null \
        | openssl x509 -noout -enddate | cut -d= -f2)
  end_epoch=$(date -d "$end" +%s)
  days=$(( (end_epoch - $(date +%s)) / 86400 ))
  if (( days < WARN_DAYS )); then
    echo "WARN: $domain expires in $days days ($end)"
  else
    echo "OK:   $domain ($days days)"
  fi
done < domains.txt

Key trick → -servername sends SNI. Without it, a shared host returns its default certificate and you check the wrong expiry. (openssl x509 -checkend 2592000 is a shortcut that gives a yes/no answer.)

All Real-World Interview questions Roadmap: Interview readiness

More on Bash scripting tasks