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.
--
William Park, Open Geometry Consulting, <openge...@yahoo.ca>
8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin
I don't know about shell but it should be simple to write the same
thing in Perl or even in C.
This particular page focuses on Windows, but the ftp site has sources in C.
David LeBlanc
Seattle, WA USA
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. :)
I didn't know about ntpdate. I don't know of any way to open sockets
from a shell script without something like perl, but maybe there is one.
Awk might be another possibility.
I know there's a full blown NTP pckage on that ftp site but I didn't
want to spend hours reading documentation and configuring some hairy
monstrosity. I don't need millisecond accuracy; I just want my
computer to know what time it is within a few seconds.
Apparently the C package has a program called ntpdate that maybe does
the right thing, but I haven't examined it.
David LeBlanc
Seattle, WA USA
> -----Original Message-----
> From: python-l...@python.org
> [mailto:python-l...@python.org]On Behalf Of Paul Rubin
> Sent: Sunday, July 07, 2002 20:39
> To: pytho...@python.org
> Subject: Re: Linux clock-setting script
>
>
Yeah, that's what I mean. I'd rather have 10 lines of Python than
20kb of C.
Or you can have just one line of shell command, like
# ntpdate host
which is (most probably) already in your distribution.
Do you have it in your distribution ? (just curious)
Best regards,
--
DIG (Dmitri I GOULIAEV)
No, not in Red Hat 7.2 or 7.3. It's probably in the big NTP package
that's downloadable/installable, but as I said, I didn't feel like
figuring all that stuff out.
I agree. Besides, the Python version is easier to make portable, which
I just did for my Windows 98 machines. (Thanks Paul!)
I changed the core of the "--set" conditional to this:
if os.name == 'posix':
os.system("/usr/sbin/hwclock --set '--date=%s'"% ct)
elif os.name == 'nt':
tt = time.localtime(t - TIME1970)
# warning: assumes M-D-Y (American) date format here!
winDate = '%s-%s-%s' % (tt[1], tt[2], tt[0])
winTime = '%s:%s:%s' % tt[3:6]
os.system("date %s" % winDate)
os.system("time %s" % winTime)
else:
print 'Unsupported OS %s, cannot set time.' % os.name
I also had to add a hash-bang line to the start, and change the
Linux path to /sbin/hwclock for my Linux boxes... Not sure that's
good, bad, or whether one should just rely on PATH to find the
executable.
-Peter
GEE Thanks!
--
Simon Foster
Cheltenham
England
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
I meant 'rdate'... a typo.
If this package has already been mentioned, sorry... I haven't followed this
thread closely.
Off-topic since it's C, but I love it.
Chris Gonnerman -- chris.g...@newcenturycomputers.net
http://newcenturycomputers.net
I've seen it, but it's a tarball which you have to download and compile.
Whereas, 'netdate', 'ntpdate', and 'telnet 13' are ready to run on all
Linux distribution. I have DSL connection, so I run it once a day in
Crontab. If you dialup, then you can run it from '/etc/ppp/ip-up'.
Why do people keep saying that? Netdate and ntpdate are not on either
of the Red Hat boxes I use (one is RH 7.2 and one is 7.3).
Woo hoo! I knew about RFC 868 but it didn't occur to me to use a
telnet command in a pipeline. I thought telnet had to interact with
the control tty.
> Chris Gonnerman <chris.g...@newcenturycomputers.net> wrote:
> > I use chrony for time maintenance. If your computer has intermittent
> > Internet access (i.e. dialup) it is hands-down the best way to do it
> > IMHO.
> >
> > If this package has already been mentioned, sorry... I haven't followed
> > this thread closely.
> >
> > http://chrony.sunsite.dk/
> >
> > Off-topic since it's C, but I love it.
>
> I've seen it, but it's a tarball which you have to download and compile.
This is a problem?
> Whereas, 'netdate', 'ntpdate', and 'telnet 13' are ready to run on all
> Linux distribution. I have DSL connection, so I run it once a day in
> Crontab. If you dialup, then you can run it from '/etc/ppp/ip-up'.
True. chrony doesn't update the time by "lurches" though, but by "skew,"
which is better in most cases.
To each his own.
Not really, but there are 2 other utilities in installation CD.
>
>> Whereas, 'netdate', 'ntpdate', and 'telnet 13' are ready to run on all
>> Linux distribution. I have DSL connection, so I run it once a day in
>> Crontab. If you dialup, then you can run it from '/etc/ppp/ip-up'.
>
> True. chrony doesn't update the time by "lurches" though, but by "skew,"
> which is better in most cases.
I think all does "skewing" if time difference is small enough (I think
0.5s).
The rpm package might be called ntpd or xntpd, or some other variant.
One problem with rpm is that if a file is not on the installed system, you
have to jump through some loops to figure out which package it is supposed
to come from. Hopefully the eventual CPyAN would be able to handle such
queries in an easy way.
Huaiyu