Bash
public
Clock Sync Check
Share this script safely, inspect its metadata, and copy the exact command you need.
Ready to run
One-liner
curl -fsSL https://runny.sh/r/58B1N0BK72NF | bash
Current version: 1.1 · Updated by Godmode · 2026-09-07 02:38:59.169
At a glance
Script metadata
Readable before runnable
Preview
#!/usr/bin/env bash
# Clock sync check
# Read-only: reports timedatectl / NTP sync state. Warns if the clock is not synced.
# Exit 0 if healthy, 1 if NTP is off or unsynced, 2 if no time tool is available.
# Hosted on Runny.sh. Review the script page before you run it.
set -u
status=0
note() { printf '%s\n' "$*"; }
bump() {
case $1 in
crit) status=2 ;;
warn) [ "$status" -lt 1 ] && status=1 ;;
esac
}
note "=== Clock synchronization ==="
note "Host: $(hostname 2>/dev/null || printf unknown)"
note "Local: $(date -u '+%Y-%m-%dT%H:%M:%SZ' 2>/dev/null || date)"
note ""
if command -v timedatectl >/dev/null 2>&1; then
timedatectl status 2>/dev/null | while IFS= read -r row; do
note " ${row}"
done
note ""
ntp=$(timedatectl show -p NTP --value 2>/dev/null || true)
synced=$(timedatectl show -p NTPSynchronized --value 2>/dev/null || true)
note "NTP: ${ntp:-unknown}"
note "Synced: ${synced:-unknown}"
if [ "${synced}" = "yes" ]; then
note " OK"
elif [ "${ntp}" = "no" ]; then
note " WARNING: NTP is disabled"
bump warn
else
note " WARNING: system clock is not synchronized"
bump warn
fi
elif command -v chronyc >/dev/null 2>&1; then
chronyc tracking 2>/dev/null | while IFS= read -r row; do
note " ${row}"
done
leap=$(chronyc tracking 2>/dev/null | awk -F ': *' '/Leap status/ {print $2}')
if [ "${leap}" = "Normal" ]; then
note " OK"
else
note " WARNING: chrony leap status is ${leap:-unknown}"
bump warn
fi
elif command -v ntpstat >/dev/null 2>&1; then
if ntpstat >/dev/null 2>&1; then
note "ntpstat: synchronized"
note " OK"
else
note "ntpstat: not synchronized"
bump warn
fi
else
note "timedatectl/chronyc/ntpstat not found"
bump crit
fi
note ""
case $status in
0) note "Result: HEALTHY" ;;
1) note "Result: WARNING" ;;
*) note "Result: CRITICAL" ;;
esac
exit "$status"
Raw endpointhttps://runny.sh/r/58B1N0BK72NF
See something unsafe?
Report this script
Tell us why it should come down. Anyone can also report a URL at /abuse.