NSLU2-Linux
view · edit · print · history

(redirected from Unslung.Ntpclient)

Here is the /unslung/rc.rstimezone diversion script that I use:

 #!/bin/sh

 /usr/sbin/Set_TimeZone >/dev/null

 if [ -x /opt/bin/ntpclient ]; then
        /opt/bin/ntpclient -h pool.ntp.org -s >/dev/null
        /usr/sbin/hwclock -s >/dev/null
 else
        /usr/sbin/hwclock
        /usr/sbin/hwclock -s >/dev/null
 fi

 return 0

I also changed the hwclock entry in /etc/crontab into a ntpclient entry, and used the resling script to save my changes.


Update

The above setup is broken since it overwrites the system time set by ntpclient when executing hwclock -s. The flow of the script should be that if ntpclient is present, fetch system time using NTP and then store the updated system time to the hardware clock. If the NTP lookup fails, we must be sure that we don't store 1.1.1970 00:00 (which is the default system time) to the hardware clock, so prior to calling ntpclient, we set the system time to the hardware clock.

 #!/bin/sh
 # The lines below are probably a restitute of a user of an additional irrelevant (metalog) package 
 # They can be left commented out.
 # These line are irrelevant for the ntpscript.
 # Time to start metalog - can't start it much sooner as rc.bootbin
 # unmounts and mounts things
 # We assume that syslogd has already been disabled in /etc/inittab
 #
 # /opt/sbin/metalog --daemonize 
 #
 # Diversion script: customize before starting crond 
 #
 # Reason, update the clock from a timeserver and when needed correct the clockdrift 
 #
 # To prevent the clockdrift on the unslungfirmware 5.5 or lower enable the last comment line below,  
 # by removeing the '#' before "/opt/sbin/adjtimex -t 10000". 
 # This command set the clockdrift to the linux standard value of 10.000
 # When this command is added the clockdrift should be minimized, 
 # so you can choose to execute less time synchronisations
 # /opt/sbin/adjtimex -t 10000

 /usr/sbin/Set_TimeZone >/dev/null
 /usr/sbin/hwclock --hctosys >/dev/null

 if [ -x /opt/bin/ntpclient ]; then
        /opt/bin/ntpclient -h pool.ntp.org -s >/dev/null
        /usr/sbin/hwclock --systohc >/dev/null 
 fi

 #
 # Continue to start crond
 return 1
 # EOF - include this line

bob(tm)

  • Note: `hwclock -s` is equivalent to `hwclock --hctosys`, which would force the hardware level clock to override (write out to) the system (OS) level clock. More useful would be `hwclock -w` which is equivalent to `hwclock --systohc`, which forces the system (OS) level clock to override (write out to) the hardware level clock.

___________

I've added one missing "-" in "--hctosys" option to hwclock in script above.

You should also note that this is script, which runs only on startup so sets clock only once. If your NSLU2 runs all the time clock will have time difference (about 20 minutes after 1 day). So you should think about NTP server or running ntp client much more frequently if you want to have correct time on NSLU2. The example script now includes a clockdrift fix, which can be enabled by removing, the '#' before the /opt/sbin/adjtimex -t 10000. Clock should keep time rather well when enabled. It is commented out, because Linksys might fix it in a newer version, then it will be only usefull for the legacy users among us.

BiG?

  - aka, use cron. -Sharth

What is the thing with this metalog stuff? What is it, and how is it related to ntp?

Mark: I don't have it in my script, it is probly a system utility like a better loging deamon. I think it should be removed from the example.

Here are my cron lines to synchronize the time. Note that I disabled the default hwclock line.

  #1 * * * * root /usr/sbin/hwclock -s &>/dev/null
  11 * * * * root /opt/bin/ntpclient -h pool.ntp.org -s &>/dev/null
  12 * * * * root /usr/sbin/hwclock --systohc &>/dev/null

Simon


The current package (as of January 2006 and firmware 5.5-beta) installs /opt/etc/cron.d/ntpclient which does the hourly ntp update. All that you need to do then is add a redirect script to set the time at boot and use the following modified cron line for hwclock:

  22 * * * * root /usr/sbin/hwclock --systohc &>/dev/null

NOTE: see Debug Crontab Problems article to read more on crond and cron. You MUST install cron ipkg package in order for ntpclient to work properly.

Here's my /unslung/rc.rstimezone script:

 #!/bin/sh
 /usr/sbin/Set_TimeZone >/dev/null
 if [ -x /opt/bin/ntpclient ]; then
        /opt/bin/ntpclient -h pool.ntp.org -s >/dev/null
        /usr/sbin/hwclock --systohc >/dev/null 
 fi
 return 0

I discovered that when I executed the /usr/sbin/hwclock --systohc command, I still got the message:

  Timed out waiting for time change.

Google brought me to the possible cause of the problem (via http://www.nslu2-info.de/forum/showthread.php?t=4264, German site): the battery might not make contact. Solution: Open the NSLU2 case and bend the metal strips under the battery a little. After that everything worked fine with me.


Solution posted above worked for me. I had my slug open to de-underclock it and saw that the battery was not firmly in place. After pressing it tightly and bending the metal strips a bit, it worked fine. My slug is keeping time after reboots and I can sync the time with /usr/sbin/hwclock --systohc

view · edit · print · history · Last edited by Marco.
Based on work by avgjoe, Darek, Julius, Rob Lockhart, Mark, VivekKhera, Simon Budig, Sharth, BiG, bobtm, anonymous, ju55i, rwhitby, and scott.
Originally by rwhitby.
Page last modified on September 01, 2008, at 12:40 AM