Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (3) </ 1 2 [3] >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: simple script to set system clock, not exact as ntp client but good enough< Next Oldest | Next Newest >
roberts Offline

Group: Members
Posts: 4983
Joined: Oct. 2003
Posted: Feb. 21 2007,14:52 QUOTE

I have updated my Lua script so that the NIST timeserver can be specified and also the initial connection timeout defaults to 5 seconds but can be user specified as well.

Code Sample
#! /bin/lua
This lua script based in part of the idea expressed in
the bash script from newOldUser of the damnsmall linux forums
by Robert Shingledecker - 2007/02/17

Usage: sudo gettime.lus {nist_time_server} {timeout-in-secs}


This script gets time information from an NIST time server
in universal time format. It then rearranges it into
the format that the date command uses
and issues the date command.

An internet connection must be available

 sample of returned information follows
54144 07-02-13 16:14:43 00 0 0  95.3 UTC(NIST) *

host = arg[1] or ""
port = 13
timeout = arg[2] or 5.00
target = {10,13,16,19,7,22}
date = ""

timeserver = socket.tcp()
_,err = timeserver:connect(host,port)
if err then
  print("Could not connect "..err)
_,err = timeserver:send("anything\n")
if err then
  print("Error in sending "..err)
print("Requesting time from: "
while 1 do
  line,err = timeserver:receive('*l')
  if err then
     print("Error in receiving "..err)
  if string.find(line,"UTC") then
     for i = 1, 6 do
        if i == 5 then date = date .. "20" end
        if i == 6 then date = date .. "." end
        date = date .. string.sub(line,target[i],target[i]+1)
     os.execute("date -u "

Please choose a timeserver nearest to you so that we all don't gang up on one. See the URL embedded for a list.
Back to top
Profile PM WEB 
WDef Offline

Group: Members
Posts: 798
Joined: Sep. 2005
Posted: Feb. 21 2007,21:21 QUOTE

WDef,  Sorry about being offtopic

No, no you misunderstand!  It was ME that was offtopic - I was posting about not seeing you 'round the forum for a while!  I don't think there's anything 'offtopic' about your post.  I wasn't clear I know.

Anyway - keep up the scripting, let's see the other efforts :=)
Back to top
Profile PM 
11 replies since Feb. 17 2007,17:18 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (3) </ 1 2 [3] >/
reply to topic new topic new poll
Quick Reply: simple script to set system clock

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code