I am working on an embedded OpenSUSE 12.3 system that allows the user to configure (one) the NTP server address. I need to be able to give user feedback on how everything happens in terms of communication with the specified server. Is the server address valid? Could NTP contact the server? Is he requesting a server? Or are we fully synchronized? (Note: once NTP thinks it's in sync, then I don't care how synchronized it is.)
Now I have written a bash script to parse the output ntpq -np:
- If the output contains
"ntpq: read: Connection refused", then ntpd does not work - If the output contains
"No association ID returned", then the server address is invalid - If the output contains
".INIT.", then ntpd is not yet connected to the server - If the output does NOT contain a line starting with
"*", then we request a server - Otherwise, we are synchronized.
Clearly, this is a pain in the rear and highly platform dependent, and I would like to have a better solution.
I understand that there is libntpq.a inside the built-in ntp source tree, which can be used by external applications, but until an official release appears that simply switches to a new taste of platform dependence.
Is there an official way to determine the current NTP client communication state? Once again, only one server will be configured.