What's the easiest way to make Busybox keep correct time?

Isaac Dunham ibid.ag at gmail.com
Sun Aug 31 20:43:56 UTC 2014


On Sun, Aug 31, 2014 at 07:04:52PM +0000, K.S. wrote:
> As I mentioned in a previous message, I am in the process of setting up a a
> small backend receiver box for free-to-air satellite television that
> includes Busybox.  It has the ability to record programs on a schedule, and
> for some unknown reason it appears the designers forgot to implement a way
> to keep the time set correctly.  Right now it appears to be losing about one
> second per hour, give or take a little, which means that after a couple of
> days it's a full minute off, which is really bad when you are trying to
> accurately schedule recordings.
> 
> I read in one of these threads that I can correct the time by entering this
> at the command prompt:
> 
> ntpd -q -p pool.ntp.org
> 
> And that does work, but it only sets the time once, and does not keep the
> time accurate over any long period (is that because of the -q option?)

Yes, it's because of the -q option; remove it if you want ntpd to run
as a daemon.

> Anyway, what I really want to know is, what's the easiest way to make this
> device keep accurate time?  I assume that I need something that will run in
> the background and periodically query the time server and adjust the time,
> and also some way to make sure that gets started after every reboot.  This
> seems like this should be very easy, but I'll ask you experts, what would be
> the easiest or best way?
> 
> I will note that it does not appear as if crontab is fully implemented,
> because if I try to run crontab with the -l or -e option it displays,
> "crontab: can't change directory to '/var/spool/cron/crontabs': No such file
> or directory".  So if there is a way to do this that doesn't involve using
> crontab, that might be better, although reliability is my #1 concern.
> 
Put a line starting ntpd in the appropriate init script or
add an init script starting it.
I can't tell you what this looks like in more detail, because I have no
idea what init system you use.

You do not want to run ntpd from cron; busybox cron eventually gives up 
if there's too big a jump in time. (At least, that's how I interpret
the logs I've had...)


Now, if you want cron to work...:
ps -ef |grep [c]rond
If there's a '-c /path/to/crontabs', you need to pass that path to crontab:
crontab -e -c /path/to/crontabs
(-c ... replaces /var/spoolcron/crontabs with ...)

If there's no process, check whether the init scripts start crond:
grep -r crond /etc

If they start it with a -c option pointing to a non-existant directory
or without -c, create the appropriate diretory.
Then run crontab -e as root and save it, whether or not it says something
meaningful (a commented-out line is fine).
If there are no init scripts, you will need to create one as well as the
proper directory.


HTH,
Isaac Dunham



More information about the busybox mailing list