[ntp:questions] ntpq -p command query

A C agcarver+ntp at acarver.net
Wed Jul 31 08:04:53 UTC 2013


On 7/31/2013 00:26, Biswajit Panigrahi wrote:
> Hi ,
> Basically my intention is to get notification in client when ever the connection between server changes(Ex-lan connectivity OR ntp server itself is down).For that I am doing the following step:
>
> In client:
> 1.Execute ntpq -c associations
> 2.Get the data in status field
> 3.If there is any change in that field ,then collect the 4th bit of that.(Ex:f69a & 1000)
> 4.If its 1 then reachable else unreachable.
>
> 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.

#!/bin/bash
/bin/ping -c 5 -i 5 server_ip > /dev/null || echo failed

Assuming bash is used, this pings the server (dumping the output of ping 
since it is not needed), checks the exit status and prints the word 
"failed" if the ping fails.  The exit status is zero if the ping 
succeeds and non-zero if it fails.

All this assumes that the servers you're attempting to test are 
controlled by you or your employer.


More information about the questions mailing list