Code Sample |
#! /bin/bash version="1.00" scriptName="getTime.sh" # # This script gets time information from time.nist.gov in # universal time format. It then rearranges it into # the format that the date command uses MMDDhhmmCCYY.ss # and issues the date command as super user. # # 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) * #0----0----1----1----2----2----3----3----4----4----5 #0----5----0----5----0----5----0----5----0----5----0 # vFound="" telnet time.nist.gov 13 > nistTime.txt date vFound=$(cat nistTime.txt | grep "UTC(NIST)") if [ ! -z "$vFound" ]; then vDateTime=${vFound:9:2}${vFound:12:2}${vFound:15:2}${vFound:18:2}"20"${vFound:6:2}"."${vFound:21:2} sudo date -u "$vDateTime" #echo "$vDateTime" fi date |
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 # This script gets time information from time.nist.gov in # universal time format. It then rearranges it into # the format that the date command uses MMDDhhmmCCYY.ss # and issues the date command as super user. # # 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) * #1---0----1----1----2----2----3----3----4----4----5 #1---5----0----5----0----5----0----5----0----5----0 # --]] host = "time.nist.gov" port = 13 target = {10,13,16,19,7,22} date = "" timeserver,err = socket.connect(host,port) if err then print("Could not connect "..err) os.exit(1) end _,err = timeserver:send("anything\n") if err then print("Error in sending "..err) os.exit(1) end timeserver:settimeout(0.10) while 1 do line,err = timeserver:receive('*l') if err then print("Error in receiving "..err) os.exit(1) end 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) end os.execute("date -u "..date) os.exit(0) end end |