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

1

1 Answer 1

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.

2
  • 4
    ntpdate ships with ntp package. Commented Oct 27, 2022 at 1:49
  • 1
    If you're not root, use ntpdate -qu pool.ntp.org (etc.). The -u flag tells ntpdate not to try to bind to a privileged port. (Actually you can always use -u, whether or not you're root.) Commented Apr 22, 2024 at 8:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.