[ntp:questions] ntpq -p command query

detha detha at foad.co.za
Thu Aug 1 18:54:17 UTC 2013


On Wed, 31 Jul 2013 08:04:53 +0000, A C wrote:

> On 7/31/2013 00:26, Biswajit Panigrahi wrote:
>> But the problem I am facing is:
>> Whenever the connectivity between the server goes down, the status field
>>  will not change immediately. My observation was whenever the reach
>> field of ntpq -p command comes to zero then only the status field
>> changes. That's why I was trying to reduce the time gap.
>>
>> If My approach is not correct then please suggest me the other approach.
> 
> You are making it far too complex and using the wrong tool for the job.
>   If you want to know whether the connection between two machines goes
> down, use the right tool for the job.  Tools like ping and traceroute, for
> example, will tell you instantaneously if there is a connection problem. 
> Use ping to probe the other server several times (assuming the other
> server is yours.)  If you get no response, the connection failed.

Ping-able network connection and a responsive ntpd on the other end is not
the same thing. There are devices in our network that can get time from
the primary NTP server, but not ping it, and vice versa. It all depends on
network/firewall setup. 

Without a full monitoring system in place I would suggest something like
ntpq -p server 2>/dev/null | grep '^\*' >/dev/null || echo "Fail"

That will tell you that there /is/ an ntpd listening, we can talk to it,
and it is synchronized to something. If it fails, it's time for
ping/traceroute and tcpdump. It would have been easier if ntpq had a
zero/nonzero exit status to check, but on at least one of my systems
it always returns 0, success or not.

-d



More information about the questions mailing list