Moxa W321-LX [35/80] Updating the time automatically

Moxa W341-LX [35/80] Updating the time automatically
W321/341 Linux Managing Embedded Linux
3-9
Visit http://www.ntp.org for more information about NTP and NTP server addresses.
10.120.53.100 PuTTY
root@Moxa:/etc/rc.d/rc3.d# ntpdate 192.168.1.97
Looking for host 192.168.1.97 and service ntp
host found : 192.168.1.97
18 Mar 19:30:36 ntpdate[192]:
step time server 192.168.1.97 offset
211195575.886041 sec
root@Moxa:/etc/rc.d/rc3.d# hwclock -w
root@Moxa:/etc/rc.d/rc3.d# hwclock
Mon Mar 18 19:30:46 2013 0.000000 seconds
NOTE
Before using the NTP client utility, check your IP and DNS settings to make sure that an Internet connection is
available. Refer to Chapter 2 for instructions on how to configure the Ethernet interface, and see Chapter 4 for
DNS setting information.
Updating the Time Automatically
In this subsection, we show how to use a shell script to update the time automatically.
Example shell script to update the system time periodically
#!/bin/sh
ntpdate time.nist.gov
# 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 –-systohc
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. E.g., fixtime
How to run the shell script automatically when the kernel boots up
Copy the example shell script fixtime to directory /etc/init.d, and then use chmod 755 fixtime to change
the shell script mode. Next, use vi editor to edit the file /etc/inittab. Add the following line to the bottom
of the file:
ntp : 2345 : respawn : /etc/init.d/fixtime
Use the command #init q to re-init the kernel.

Содержание

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

Скачать
Случайные обсуждения