Linux clock-setting script

William Park opengeometry at NOSPAM.yahoo.ca
Tue Jul 9 00:51:34 EDT 2002


William Park <opengeometry at nospam.yahoo.ca> wrote:
> Paul Rubin <phr-n2002b at nospamnightsong.com> wrote:
>> William Park <opengeometry at NOSPAM.yahoo.ca> writes:
>>> >  http://www.nightsong.com/phr/python/setclock.py
>>> > 
>>> > I find it pretty useful for adjusting my computer clock every now and
>>> > then, without the hassle of setting up a real NTP system.
>>> 
>>> Thanks for the pointer, Paul.  Exactly what I needed.  Do you know any
>>> pure shell script that does the same thing?  I don't have Python
>>> installed on every machine.
>> 
>> I don't know about shell but it should be simple to write the same thing
>> in Perl or even in C.  
> 
> I've found a partial solution.  I'm now using, ntpdate time.apple.com
> time.windows.com time.nrc.ca ntp1.cmc.ec.gc.ca where 'ntpdate' comes from
> NTP package.  Still, shell solution would be desireable, because I
> sometime don't have access to Perl, Python, or NTP packages.  But, I do
> have access to shell all the time.
> 
> I'll update when I find solution. :)

Found it!

For those of you who need to set system clock only periodically, say once a
day, here are methods that are available:

1.  Network Time Protocol (RFC-1305, port 123):
	ntpdate time.nist.gov ...

    'ntpdate' is part of standard NTP package on any Linux distribution.

2.  Time Protocol (RFC-868, port 37):
	netdate time.nist.gov ...

    Slackware includes 'netdate' as part of base TCP/IP package.  You can
    use 'rdist' from
	ftp://ibiblio.org/pub/Linux/system/network/misc/
    but it is now deprecated in favour of 'netdate'.

3.  Daytime Protocol (RFC-867, port 13):
	date -u -s `telnet time.nist.gov 13 | grep UTC | cut -f2,3 -d' '`

    This is shell solution that I've been after.

Of course, one the system clock is set, you can set the CMOS clock by
    hwclock --systohc

-- 
William Park, Open Geometry Consulting, <opengeometry at yahoo.ca>
8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin



More information about the Python-list mailing list