I am running busy box on an embedded platform. I would like to set the date on the box properly each time I reboot the hardware. I have no way to save the time persistently, so am reduced to setting the time each time. I have LAN connectivity for it, but no SSH. My current hack for this is to redirect the output of 'date' to a file on my PC, access that file from my hardware platform through tftp, and then somehow parse the file, use its contents and then to set the date. I have no idea how to get the string from the file and then set it using the 'date' command. Any help would be appreciated. Any other way to set the date would be get. I have tried using ntpd, but that fails due to lack of internet connectivity
|
Using a cron job, you could write a file to your /tftp directory with a granularity of 1 minute.
The contents of that file are a single value, which is formatted conveniently in the same format the date command needs to set the date/time.
On the busybox side of things, you could just tftpget the file, and process it
If HTTP is an option, you could set up a php script that just returned the date when called, and have your script on the busybox side poll that URL, and process the result. The granularity of the date would be closer, in that case. With TFTP, you'll be within 1 minute. Hopefully that's close enough. |
|||
|
|
NTP (Network Time Protocol) is the standard way of getting the date. On a BusyBox system, you might want to use ntpclient. You'll need an NTP server somewhere on the network. |
|||
|
|
|
To use the Network Time Protocol on the embedded machine, just run some lightweight NTP daemon (server) locally on your LAN - for example on the machine that you are currently trying to use for synchronization. Most, if not all distributions have packages like openntpd or ntp that provide an NTP server. If you still insist on parsing the output of |
|||
|
|
As per your comment.
The solution to your problem is to setup another machine on your LAN as a time server -- that machine should (preferably but not strictly necessarily) have access to internet, so that it itself can synchronize with an external time source. the NTP server can configured to broadcast the clock on the LAN (1 UDP packet every 5 minutes or so), or it can just be a server which is accessed on request -- your choice. The your busy-box which has LAN access (but not internet access) can be installed with a NTP client which picks up the time from the broadcast OR just asks your LAN server for the time when needed. |
|||
|
|
|
You can also use:
|
||||
|
|
rdate -s. That was before ntp came along. – Paul Tomblin Oct 25 '11 at 12:57rdatefor the simple clock corrections that I need on my desktops. – rozcietrzewiacz Oct 25 '11 at 13:04