Time sync

Sasha Pachev sasha at asksasha.com
Thu Aug 25 22:27:56 MDT 2005

Hello, everyone:

Lately I've been struggling trying to find a time server that would be both free 
and reliable ( as in you can count on it being up). I do not really need a very 
high precision - a couple seconds off is OK. So I came up with the following hack:

#! /usr/bin/perl

use LWP::UserAgent;

$url = "http://nist.time.gov/timezone.cgi?Mountain/d/-7/java";

$ua =  LWP::UserAgent->new;
$resp = $ua->get($url);

if ($resp->is_success)
   $resp->content =~
   /NISTSendTime\s*=\s*new\s*Date\s*\(\s*\"([\w,: ]+)\"/;
   $d = $1;
   $d =~ s/\"//g;
   system("/bin/date -s \"$d GMT\" && /sbin/hwclock --systohc ");

However, it would be nice to know if there is a better solution.

Sasha Pachev
AskSasha Linux Consulting

More information about the PLUG mailing list