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:
- Check the ntp offset with the SBC and ntp servers
- Then, record the offset in a variable
- 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.
- It will only increase at maximum 60 seconds every hour
- 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 :
- Is there any other way to do the incremental time jump similar to this?
- I notice that ntpdate has -B function that will do the incremental time update, but I failed to use this on the SBC. What is the correct method to use this switch? Or I misunterstood it functionality?
- Can adjtimex achieve this purposes?
- Here is my complete bash script if any of you need it (too long to paste here),
http://pasted.co/65beb3db [password : 123456]