Forum Discussion
youssef1
Apr 23, 2019Cumulonimbus
Hi,
You have 2 way to achieve your need:
You can use ntpq for that.
First, calculate the offset and store it in a var:
ntp_offset=$(ntpq -pn | /usr/bin/awk 'BEGIN { offset=1000 } $1 ~ /\*/ { offset=$9 } END { print offset }')
- Server OK when: ntp_offset < 1000
- Server unsynchronised when: ntp_offset >= 1000
The second way is to use ntpstat:
-
Output when ntp is synched: synchronised to NTP server (10.1.11.33) at stratum 2 time correct to within 107 ms polling server every 1024 s
-
Output when ntp is unsynchronised:
unsynchronised
For more info: https://www.cyberciti.biz/faq/linux-unix-bsd-is-ntp-client-working/
Regards