Moxa V2403-C7-W-T [11/90] Example shell script for updating the system time periodically

Moxa V2403-C7-W-T [11/90] Example shell script for updating the system time periodically
V2403 Series Linux Software Software Configuration
2-5
Visit http://www.ntp.org for more information about NTP and NTP server addresses.
root@Moxa:~# date ; hwclock
Wed Dec 16 16:36:12 CST 2009
Wed 16 Dec 2009 03:38:13 AM CST -0.016751 seconds
root@Moxa:~#
root@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
root@Moxa:~#
root@Moxa:~# hwclock -w
root@Moxa:~# date ; hwclock
Wed Dec 16 03:51:07 CST 2009
Wed 16 Dec 2009 03:51:07 AM CST -0.016771 seconds
root@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 updating the system time periodically
#!/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
Copy the example shell script fixtime to directory /etc/init.d, and then use chmod 755 fixtime to change
the shell script mode.
moxa@Moxa:~# chmod 755 fixtime
Next, use vi editor to edit the file /etc/inittab.
moxa@Moxa:~# vi /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-initialize the kernel.
moxa@Moxa:~# init q

Содержание

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

Скачать