summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Thomas <james.thomas@codethink.co.uk>2012-09-18 12:39:29 +0000
committerJames Thomas <james.thomas@codethink.co.uk>2012-09-18 12:39:29 +0000
commite37343389d21c840d8251d7896322248b9b661d2 (patch)
tree3c6cb888472619814a38928c560211b12d7390ff
parent3232be1c49c4f57d4ccd52f4e6ae25c1dfef0cdf (diff)
downloadbusybox-e37343389d21c840d8251d7896322248b9b661d2.tar.gz
Add a script to call ntpd with a list of servers
-rwxr-xr-xscripts/ntpd-set.sh36
1 files changed, 36 insertions, 0 deletions
diff --git a/scripts/ntpd-set.sh b/scripts/ntpd-set.sh
new file mode 100755
index 000000000..3581d2421
--- /dev/null
+++ b/scripts/ntpd-set.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+max_attempts=4
+try_count=0
+
+# This script takes a list of ntp servers and passes them to ntpd to set the
+# system time. If a /etc/ntpd.conf file exists, the servers there are used,
+# if not, some default values are passed
+set_time() {
+ ntpd -n -p $1;
+ return $?
+}
+
+check_time() {
+ for arg ; do
+ echo $arg
+ if set_time $arg ; then
+ return 0
+ fi
+ done
+ # In case we are doing this before the network is up, try again
+ let try_count=try_count+1
+ if [ $try_count -lt $max_attempts ] ; then
+ sleep 2
+ check_time $@
+ else
+ return 1
+ fi
+}
+
+if [ -f /etc/ntpd.conf ]; then
+ server_list=`cat /etc/ntpd.conf | sed ':a;N;$!ba;s/\n/ /g;s/server//g'`
+ check_time $server_list
+else
+ # Use a default list if there's no config
+ check_time 0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org 3.pool.ntp.org
+fi