I'm working on an embedded OpenSUSE 12.3 system that lets the user configure the (single) NTP server address. I need to be able to give the user feedback on how things are going in terms of communicating with the specified server. Is the server address valid? Has NTP been unable to contact the server? Is it querying the server? Or, are we fully synchronized? (Note: once NTP thinks it's synchronized then I don't care just how synchronized it is.)
Right now I've written a bash script to parse the output of ntpq -np
:
"ntpq: read: Connection refused"
then ntpd isn't running"No association ID's returned"
then the server address is invalid".INIT."
then ntpd hasn't yet connected to the server"*"
then we're querying the serverClearly, this is a pain in the rear and highly platform-dependent, and I'd love to have a better solution.
I understand that there's a libntpq.a inside of a built ntp source tree that can be used by external applications, but until there's an official release then that's just switching to a new flavor of platform-dependence.
Is there an official way to determine the current communication status of an NTP client? Note again that only a single server will be configured.
How about ntpstat, would that work for you? Here are the exit/return values from the command when it's run:
Check out the page Verify that my NTP is working