10

we have bash script that configured the chrony.conf

script check if ping is ok on ntp1 and ntp2 ( ntp servers )

and then script insert the ntp servers to /etc/chrony.conf ( only if ping success )

example from bash script:

ping -c 1 ntp1

if [[ $? -eq 0 ]];then echo "server ntp1 iburst" >> /etc/chrony.conf else echo "sorry so much but no ping to ntp1 server , /etc/chrony.conf will not configured " exit 1 fi

ping -c 1 ntp2

if [[ $? -eq 0 ]];then echo "server ntp2 iburst" >> /etc/chrony.conf else echo "sorry so much but no ping to ntp2 server , /etc/chrony.conf will not configured " exit 1 fi

the problem is that sometimes the user decided to disable the ping or icmp

then in that case the scenario that we checked the ping isn't relevant , and we cant add the lines to /etc/chrony.conf

so we want to know how to test the ntp1 and ntp2 servers in order to add ntp1 and ntp2 to chrony configuration

for example if ntp1 and ntp2 not seems to be as ntp servers , then we will not add them to chrony configuration

King David
  • 1,001

1 Answers1

14

An ntp server can be tested by asking it for the date using the ntpdate command.

For example:

ntpdate -q pool.ntp.org

The parameter -q is for query only, don't set the clock.

The command will return the exit code of 0 if successful.

harrymc
  • 498,455