Alert when any certificate under `/etc/letsencrypt/live` expires within 21 days.
IntermediateScenarioScenarios: health checks, monitoring and alerts
Answer
Situation read → openssl x509 -checkend does the date math and returns a clean exit code.
What I'd do →
rc=0
for cert in /etc/letsencrypt/live/*/fullchain.pem; do
[[ -e $cert ]] || continue
if ! openssl x509 -checkend $((21 * 86400)) -noout -in "$cert" >/dev/null; then
end=$(openssl x509 -enddate -noout -in "$cert" | cut -d= -f2)
echo "CRIT ${cert%/fullchain.pem}: expires $end"
rc=2
fi
done
exit "$rc"
-checkend Nexits 1 if the cert expires within N seconds.- Also check what the server actually serves (
openssl s_client -connect host:443 -servername host), since a renewed file is useless if nginx was never reloaded.
Why → Expired certificates cause total outages and are 100% predictable.
Interview tip → Mention checking the served certificate, not only the file; renewal without reload is a common miss.
More on Scenarios: health checks, monitoring and alerts
You are asked for a host health-check script covering disk, memory, systemd services and an HTTP endpoint. How do you design it?IntermediateYour disk alert fires and clears every few minutes around 80%, spamming Slack. How do you fix the alerting?AdvancedA server reports `No space left on device` but `df -h` shows 40% free. What would you add to the health checks?BeginnerA developer wrote a Bash loop that restarts the app whenever its process disappears. What do you suggest instead?IntermediateYou suspect a memory leak in a service. How do you collect evidence with a script before involving developers?AdvancedHow do you know a scheduled job actually ran, not just that it did not report failure?Intermediate