This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes Check current time on two different Linux Box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Check current time on two different Linux Box" Watch "Check current time on two different Linux Box" New topic
Author

Check current time on two different Linux Box

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9344
    
    2

Guys,

Is there a way to check the current time on two different Linux box from a thrid machine? I want to know if the two different Linux Boxes have the same time and if not what is the time difference between the two? I want to check this from a Windows client. Is there a way to do this?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5811
    
    7

Are the boxes running a network time protocol server (ntpd)? If so, you could check via port 123. (http://en.wikipedia.org/wiki/Network_Time_Protocol)

Another way is to run an ssh command to obtain the time. Of course then ssh would have to be open and available.

There are probably several other ways.


JBoss In Action
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950
    
  19

Actually, rather than checking times, you should just go ahead and synchronize them. As Peter mentioned, Linux comes with NTPD, which can synchronize the system times to a master standard (Tier 1 includes the atomic clocks at NIST) within a dozen milliseconds or so. If you make one or more of the Linux boxes NTP peers, probably even microsecond accuracy, since the main obstacles are network latencies followed (distantly) by CPU overhead. You can also connect your Windows network to a timeserver.


Customer surveys are for companies who didn't pay proper attention to begin with.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Some Linux distros do not install the NTP client automatically, but its always easy.

Rather than directly contacting one of the first tier servers, you should use one of the many NTP server pools. This cuts load on the tier 1 servers and distributes it over the whole web. See http://www.pool.ntp.org/en/use.html

Once you set it up, the computer will automatically stay in perfect sync.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950
    
  19

Pat Farrell wrote:Some Linux distros do not install the NTP client automatically, but its always easy.

Rather than directly contacting one of the first tier servers, you should use one of the many NTP server pools. This cuts load on the tier 1 servers and distributes it over the whole web. See http://www.pool.ntp.org/en/use.html

Once you set it up, the computer will automatically stay in perfect sync.



Tier 1 should be avoided unless you're, say, Lawrence Livermore labs (who for all I can recall is Tier 1 themselves). Pools are recommended, but if not, use a Tier 2 server. Incidentally, a few years back, a router company hard-wired in a single time server, and unfortunately sold so many of those routers that they basically DDOS'ed it.

Horologists would take exception to "perfect sync". Thanks to various fuzz factors, anyone who's not wired directly into an atomic clock is going to float around the ideal, and even there, things like network environment, temperature, humidity, etc. factor in. What is horology for, if not splitting hairs (or at least seconds )?

Since most of us don't require QUITE that much precision, NTP attempts to make the best of a bad situation. Given multiple time references, it achieves the best consensus it can. It also tunes local drift correction, since they figure that most of us are more interested in using the low-overhead hardware time services of our computers more than we are in computing the precise time to the split nanosecond.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Tim Holloway wrote:Thanks to various fuzz factors, anyone who's not wired directly into an atomic clock is going to float around the ideal, and even there, things like network environment, temperature, humidity, etc. factor in. What is horology for, if not splitting hairs (or at least seconds )?


I wonder... suppose you have your own atomic clock. If "you" is not NIS&T, its not official. It might be right, or it might be off a few split hairs. So you need to network your atomic clock to the official time. Once you do that, you have to deal with latency, error retransmission, etc. This raises questions of what is the error induced by link. To address this, you probably will want to setup a network connection to other official times, such as the one in Paris. Pretty soon, you are talking about NTP

For years, I've been running a pool server in my basement. I'm located "inside the beltway" in the Washington DC area, less then 7 miles from the US Naval Observatory, which is one of the official time keepers. I contacted them, and several other similar services near where my server is, and got permission to have my pool server connect directly to the Tier 1 servers. Of course, this just means that the tier 1 servers are in the pool that my server uses, and it used the standard NTP protocols.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Check current time on two different Linux Box
 
Similar Threads
How to have Weblogic running on two IP addresses?
How to auto start a process when Linux starts or reboot?
using current window info in new window
NIC Card Problem
How can I practice/sharpen my *nix skills?