User`s manual
ThinkCore IA241/240 Linux User’s Manual 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:~# date ; hwclock
Sat Jan 1 00:00:36 CST 2000
Sat Jan 1 00:00:37 2000 -0.772941 seconds
root@Moxa:~# ntpdate time.stdtion.gov.tw
9 Dec 10:58:53 ntpdate[207]: step time server 220.130.158.52 offset 155905087.9
84256 sec
root@Moxa:~# hwclock -w
root@Moxa:~# date ; hwclock
Thu Dec 9 10:59:11 CST 2004
Thu Dec 9 10:59:12 2004 -0.844076 seconds
root@Moxa:~#
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.
Cron—Daemon to Execute Scheduled Commands
Start Cron from the directory
/etc/rc.d/rc.local
. It will return immediately, so you don’t need to
start it with ‘&’ to run in the background.
The Cron daemon will search
/etc/cron.d/crontab
for crontab files, which are named after
accounts in /etc/passwd.
Cron wakes up every minute, and checks each command to see if it should be run in the current
minute. When executing commands, output is mailed to the owner of the crontab (or to the user
named in the MAILTO environment variable in the crontab, if such a user exists).
Modify the file
/etc/cron.d/crontab
to set up your scheduled applications. Crontab files have the
following format: