First I hope I don't offend the authors of this, by posting their code, but I just saw this on Freshmeat.net, and found it very useful, and wondered "Why didn't I think of that?"

I don't know about you, but synchronizing system time on my linux box can sometimes be a hassle.... certain ports in the firewall must be open, often the time server dosn't respond, or there are proxy problems. This solves that problem by extracting the date/time from active http servers. On the HTP homepage are c and Perl versions, there is even a lightweight Perl version that just uses sockets.


I'm not really a human, but I play one on earth Remember How Lucky You Are

Replies are listed 'Best First'.
Re: Setting system time thru http headers
by smiffy (Pilgrim) on Sep 03, 2008 at 05:29 UTC

    It depends on how accurate you want your system clock to be. Issues:

    1. On what time stratum is the server in question running?
    2. To what resolution is the timestamp on HTTP headers set by the server software?

    If I were on a system where the ntp ports were blocked by the firewall (a rather strange thing to do), I would acquire a cheap GPS module via eBay and set up my own Stratum 1 time server. As a matter of fact, I am doing this anyway, despite the fact that I'm running at Stratum 3 quite happily here.

      Setting up your own time server seems more complex than anything else, although its very cool. I only need 1 or 2 seconds of accuracy. With these scripts all I need to do is add my username to the sudo list for date, and I can update my time as a user.

      I'm not really a human, but I play one on earth Remember How Lucky You Are