Write a quick check that a host's clock is synchronized.
BeginnerScenarioScenarios: health checks, monitoring and alerts
Answer
Situation read → Clock skew breaks TLS, Kerberos, distributed locks, log correlation and AWS request signing (RequestTimeTooSkewed).
What I'd do →
synced=$(timedatectl show -p NTPSynchronized --value)
[[ $synced == yes ]] || { echo "CRIT clock not NTP-synchronized"; exit 2; }
if command -v chronyc >/dev/null; then
offset=$(chronyc tracking | awk '/^System time/ {print $4}')
awk -v o="$offset" 'BEGIN {exit !(o > 0.5)}' && { echo "WARN offset ${offset}s"; exit 1; }
fi
echo "OK clock synchronized"
Why → Time problems produce confusing errors far from the root cause.
Interview tip → Mention AWS's RequestTimeTooSkewed error as a real-world symptom.
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?BeginnerAlert when any certificate under `/etc/letsencrypt/live` expires within 21 days.IntermediateA 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?Advanced