Moxa V2401-CE [17/108] Example shell script for updating the system time periodically

Moxa V2401-LX [17/108] Example shell script for updating the system time periodically
V2401/2402 Series Linux User’s Manual Software Configuration
2-10
NTP Client
The V2401/2402-LX has a built-in NTP (Network Time Protocol) client that is used to initialize a
time request to a remote NTP server. Use ntpdate to update the system time.
#ntpdate time.stdtime.gov.tw
#hwclock –w
Visit http://www.ntp.org for more information abou
t NTP and NTP server addresses.
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.
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:~#

Содержание

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

Скачать