Linux clock-setting script
Peter Hansen
peter at engcorp.com
Mon Jul 8 08:37:00 EDT 2002
Paul Rubin wrote:
>
> Dmitri I GOULIAEV <dmitri.gouliaev at telkel.net> writes:
> > 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)
>
> 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
More information about the Python-list
mailing list