I am running Ubuntu on an ARM based embedded system that lacks a battery backed RTC. The wake-up time is somewhere during 1970. Thus, I use the NTP service to update the time to the current time.
I added the following line to
sudo ntpdate -s time.nist.gov
However, after startup, it still takes a couple of minutes until the time is updated, during which period I cannot work effectively with
How can I force a clock update at any given time?
UPDATE 1: The following (thanks to Eric and Stephan) works fine from command line, but fails to update the clock when put in
$ date ; sudo service ntp stop ; sudo ntpdate -s time.nist.gov ; sudo service ntp start ; date Thu Jan 1 00:00:58 UTC 1970 * Stopping NTP server ntpd [ OK ] * Starting NTP server [ OK ] Thu Feb 14 18:52:21 UTC 2013
What am I doing wrong?
UPDATE 2: I tried following the few suggestions that came in response to the 1st update, but nothing seems to actually do the job as required. Here's what I tried:
- Replace the server to
- Use explicit paths to the programs
- Remove the
ntpservice altogether and leave just
sudo ntpdate ...in
- Remove the
sudofrom the above command in
Using the above, the machine still starts at 1970. However, when doing this from command line once logged in (via
ssh), the clock gets updated as soon as I invoke
Last thing I did was to remove that from
rc.local and place a call to
ntpdate in my
.bashrc file. This does update the clock as expected, and I get the true current time once the command prompt is available.
However, this means that if the machine is turned on and no user is logged in, then the time never gets updates. I can, of course, reinstall the
ntp service so at least the clock is updated within a few minutes from startup, but then we're back at square 1.
So, is there a reason why placing the
ntpdate command in
rc.local does not perform the required task, while doing so in
.bashrc works fine?