linuxbashntpbusyboxntpd

How to do incremental time leap to avoid data loss


Background : Hi, I am currently working with an old Linux SBC system. It uses BusyBox v1.00-rc2 which is old and had limited functionality. (nope, upgrade is not an option). This SBC was hooked up with several sensor, record the value and time stamped it.

Problem : After several years, the RTC drifted from actual time and some of the SBC delay more than 1hours (slower) from the actual time.

I cannot simply do the ntpdate with the ntp servers because it will cause time jump and causing huge gap on the data monitoring log. It is not acceptable.

Solution: I had created a bash script that will:

  1. Check the ntp offset with the SBC and ntp servers
  2. Then, record the offset in a variable
  3. If the offset value is larger than 7, for example (60sec offset), the script will increase the system clock, little by little using date -s command.
  4. It will only increase at maximum 60 seconds every hour
  5. Example :
    • SBC time is 14:59:00 4th April 2016
    • Actual time from ntp servers is 15:00:00 4th April 2016
    • If I use ntpdate -q -4 utcnist2.colorado.edu it will return with 60 seconds offset
    • So, my script will only increase 7 seconds every 450 seconds
    • With this logic, SBC time will catchup with ntp time around Apr 4th 16:04:17 2016
    • The problem is, this script manage to slowly adjust the time step by step, BUT sometimes, it will go haywire and the SBC time will be faster compared to the actual time (Ntp time) and this will cause the data loss (server will ot accept if the SBC time is faster than the server time).

Questions :

http://pasted.co/65beb3db [password : 123456]


Solution

  • I have come to a conclusion regarding to this matters. There are 2 solutions (from my experience. Maybe more. Feel free to add):

    Solution 1


    Solution 2 (Which what I am using right now)

    !/bin/sh

    pid=pidof NTP_Update

    if [ -n "$pid" ] ; then echo "NTP_Update is running..." else echo "NTP_Update not running..." cd /root/script ./NTP_Update fi


    Hope this work around method will help anybody that was struggling with old busybox version.