Interview Prep/Shell Scripting/Scenarios: health checks, monitoring and alerts

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.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: health checks, monitoring and alerts