Tiny Core Linux
Tiny Core Base => TCB Talk => Topic started by: maro on September 20, 2011, 09:38:33 PM
-
The recent change (in v3.8 ) of the hard-coded DAYTIME server in '/usr/bin/getTime.sh' does not seem to have been a great improvement. At least considering my own experience of the last few days. Clearly vitex would be right to claim "I told you so" (http://forum.tinycorelinux.net/index.php/topic,10728.msg56963.html#msg56963).
Whilst I had stated in the same thread that a single user experience might not be applicable to everybody else, I also believe that a single hard coded value is less then ideal. After checking the list (http://tf.nist.gov/tf-cgi/servers.cgi) again I'd like to suggest the following patch:
--- /usr/bin/getTime.sh
+++ getTime.sh
@@ -17,4 +17,7 @@
[ "x$1" = "x-p" ] && shift && PRINT=1
-NIST="$1";[ -z "$NIST" ] && NIST="time.nist.gov"
-R=$(nc "$NIST" 13 | grep "UTC(NIST)")
+NIST="$1"
+USTIMING_SERVERS="atl chi sj" # the whole list: "atl chi la lv nj ny pa sj"
+[ -z "$NIST" ] && NIST="nist1-$( echo "$USTIMING_SERVERS" \
+ | awk '{ srand(); n = int(rand() * NF) + 1; print $n }' ).ustiming.org"
+R=$( nc -w 3 "$NIST" 13 | grep "UTC(NIST)")
if [ -n "$R" ] ; then
@@ -26,3 +29,6 @@
fi
+ date
+else
+ echo "no response from $NIST" > /dev/stderr
+ exit 1
fi
-date
It tries to address the issue by: (1) picking randomly one out of several servers from the US Time Server Foundation (http://www.ustiming.org), (2) specifying a certain wait time (i.e. 3 seconds), (3) having a defined response (i.e. an error message and an 'exit') when not having received an answer, and (4) only showing the current time stamp when a reply was received.
Please note that I've limited the list of servers to only the three (i.e. Atlanta, Chicago and San Jose) from which I managed to get DAYTIME responses. But if other users are getting a different result I'd suggest to use a fuller list (see the comment in the same line). At least point (3) and (4) would allow the user to now be clear about the success or failure of the script execution.
EDIT: Minor correction by dropping the superfluous parameter in the 'rand()' function.
-
The existing script has from the beginning accepted an argument of any desired time server.
Therefore I hardly think it is deserving of a "I toid you so", especially with all the CLI commandos that frequent this forum. Nonetheless, patch accepted. Thanks.
-
As vitex was kind enough in a PM to point out that the 'rand()' function was using a superfluous parameter I've now done that a minor adjustment to the OP. To limit future potential confusion it might be worth applying this ever so slightly modified patch.