Moxa V2616A-C8 [13/111] Updating the time automatically

Moxa V2616A-C8-LX [13/111] Updating the time automatically
V2616A Linux Software Configuration
2-6
Visit http://www.ntp.org for more information about NTP and NTP server addresses.
MOXA:~# date ; hwclock
Wed Dec 16 16:36:12 CST 2009
Wed 16 Dec 2009 03:38:13 AM CST -0.016751 seconds
MOXA:~#
MOXA:~# ntpdate time.stdtime.gov.tw
16 Dec 03:49:48 ntpdate[2510]: step time server 220.130.158.52 offset 155905087.9
84256 sec
MOXA:~#
MOXA:~# hwclock -w
MOXA:~# date ; hwclock
Wed Dec 16 03:51:07 CST 2009
Wed 16 Dec 2009 03:51:07 AM CST -0.016771 seconds
MOXA:~#
ATTENTION
Before using the NTP client
utility, check your IP address and network settings (gateway and DNS) to make
sure an Internet connection is available.
Updating the Time Automatically
This section describes how to use a shell script to update the time automatically.
Example shell script for periodically updating the system time
#!/bin/sh
ntpdate time.stdtime.gov.tw
# You can use the time server’s ip address or domain
# name directly. If you use domain name, you must
# enable the domain client on the system by updating
# /etc/resolv.conf file.
hwclock –w
sleep 100
# Updates every 100 seconds. The min. time is 100 seconds.
# Change 100 to a larger number to update RTC less often.
Save the shell script using any file name. For example, fixtime.
How to run the shell script automatically when the kernel boots up
Because the root file system is mounted in Read-only mode, we need to re-mount it using writable permission.
root@Moxa:~# mount -o remount,rw /
Copy the example shell script fixtime to the directory /etc/init.d, and then use chmod 755 fixtime
to change the shell script mode.
root@Moxa:~# chmod 755 fixtime
Next, add the following line to the bottom of the file /etc/inittab:
root@Moxa:~# echo ntp : 2345 : respawn : /etc/init.d/fixtime>> /etc/inittab
After you finish writing or modifying the code, remember to execute umount / to change the root directory
back to Read-only mode.
root@Moxa:~# umount /
Use the command #init q to re-initialize the kernel.
root@Moxa:~# init q

Содержание

Похожие устройства

Скачать