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

K.S. skyscanner at gmx.ca
Mon Sep 1 18:22:15 UTC 2014


I wanted to return to this post because of the discussion of crond:

Isaac Dunham <ibid.ag <at> gmail.com> writes:

> Now, if you want cron to work...:

I would be interested in this only because I think it might be a good idea
to run hwclock -w to update the hardware clock about once per hour.  The
only thing that concerns me about that is I don't know what would happen if
the internet were down for a while.

> ps -ef |grep [c]rond

That returns absolutely nothing.

> 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

That also returns absolutely nothing.  The init script on this system appear
to be in /etc/init.d and there's nothing in there about crond either.  If I
do "which crond" it returns /usr/sbin/crond, so the crond program exists 
 
> 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.

I suspect the reason they don't enable crond is because this is an embedded
device and I don't think it ever occurred to the designers that there might
be a use for it. When I wrote them about the script I'm using to start ntpd,
the response I got gave me the impression that nobody had considered this
use case before.  They then suggested I use hwclock -w to update the
hardware clock, which is why I think it might be a good idea, but their
suggestion was to run it at statup.  The problem is that if I only run that
at each reboot, the hardware clock will still drift away thereafter (losing
around 20 to 25 seconds per day).  So my thought is that once the system
clock is running accurately, it might be a good idea to reset the hardware
clock.  But if they have provided some mechanism to run jobs on a schedule,
I have no idea what it is.

Failing that, I suppose it would work just as well to run an "endless loop"
script at startup. I don't know offhand how to do an endless loop in a
Busybox shell script, but the idea is that it would do something like this:

sleep 3600
hwclock -w
(loop back to sleep statement - got any idea how to do this?)

This may be a bit inelegant but it should update the hardware clock once an
hour starting one hour after the system comes up.  I suppose it would be
better if before updating the hardware clock, it had a way to check that
ntpd is still working, but I don't really know how to do that either.  Of
course this assumes that during "sleep" there is no significant penalty on
the CPU.

Thanks for the suggestions on this.





More information about the busybox mailing list