...making Linux just a little more fun!
By William Park
There are 3 protocols dealing with time: NTP (port 123), Time (port 37), and Daytime (port 13). If you're connecting to the Internet periodically, then synchronizing your clock when you dial up or from crontab is good enough. This applies also to most Linux machines at home or at work, even if they are connected all the time. Here is a short tutorial on how to set your clock using these 3 protocols.
First, you need reference servers to obtain the time from. In Canada,
The time you see displayed is the CMOS clock time corrected by the drift in /etc/adjtime, so
hwclock --adjust hwclock --hctosysshould be done at boot. Once running, the system clock can be set by any one of the four following methods:
ntpdate time.nrc.ca time.apple.com time.windows.com
netdate time.nrc.ca time.nist.gov time-nw.nist.gov
set -- `nc time.nist.gov 13` date -u --set="$2 $3"
date --set="16:24:30"
hwclock --systohcwhich will update /etc/adjtime.
You can wrap it up as /etc/rc.d/rc.clock, with something like
#! /bin/sh [ -x /sbin/hwclock ] || exit 1 case $1 in start) echo "Setting system time from hardware clock." /sbin/hwclock --adjust /sbin/hwclock --hctosys ;; stop) echo "Saving system time to hardware clock." /sbin/hwclock --systohc ;; sync) /usr/sbin/ntpdate time.nrc.ca time.apple.com time.windows.com ;; *) echo "Usage: $0 {start|stop|sync}" ;; esacThen, you can call
I learned Unix using the original Bourne shell. And, after my
journey through language wilderness, I have come full-circle
back to shell. Recently, I've been patching features into Bash,
giving other scripting languages a run for their money.
Slackware has been my primary distribution since the beginning,
because I can type. In my toolbox, I have Vim, Bash, Mutt, Tin,
TeX/LaTeX, Python, Awk, Sed. Even my shell command line is in
Vi-mode.