23 September 2007

#38. Synchronize Your Clock in Linux

Note to readers: If you use Linux, as more and more people do, you're in for a special treat today! Special guest blogger, Linux wizard, and long-time FOJ (friend of Jonathan) Mark Lautman follows up on my earlier column about setting your Windows computer's clock. Take it away, Mark!

Jonathan's Tool Bar and Grill is a place where friends come to drink a few brews and watch soccer or baseball games on a plasma television over the well-stocked bar, or where intimates can catch a few minutes of privacy in a secluded booth toward the back.

However, lurking in the dark matter permeating this festive establishment is a crowd of Linux users. You can't always pick them out, because they "look and feel" like Windows users. There is one sign you can use to spot them: they don't order off the regular menu. If you listen closely, you might hear them ask the waiter for "grep" or "awk" or "gzip." I know, because I'm one of them.

The owner of the Tool Bar and Grill has granted me space to provide some Linux side dishes to the utilities he serves to the regular customers. We'll start with one of the earlier postings, on synchronizing the computer's clock (#3, 25 September 2006).

There are many distributions of Linux. If I had time, I would use KNOPPIX, Puppy, and Yellow Dog, mostly because I like their names. However, most Linux desktop users prefer Ubuntu, and that's the distribution I'll use for my examples.

Waiter, Where's My Food!?

Have you ever been in a restaurant, fuming because your order doesn't come as fast as you think it should? Maybe you've said something like, "Waiter, I ordered my eggs and toast twenty minutes ago!" The waiter replies, "No, it was only five minutes ago." Who is right?

It's the same thing with computers. Your computer says that its 8:35:00, but the news sites you visit say its 8:37:00. Who is right?

If you're running Ubuntu Linux, there is a good chance that you're wrong. When you install a fresh plate of Ubuntu piled high with strawberries and whipped cream, you don't automatically get the background process that synchronizes your computer's time with an NTP server.

To see if you have the NTP synchronization running, open a terminal and check for the ntp process.

>ps -A | grep "ntpd"

If you get a response, something like 3514 pts/1 00:00:00 ntpd, then you're in business. Your computer's clock is automatically synchronized. If you don't get a response, then you're computer's clock is in its own time-space warp, unaware of the universe around it. Just for kicks, let's check how far off my computer is using the ntpdate command with the q option.

>sudo ntpdate -q pool.ntp.org
server, stratum 2, offset 116.856912, delay 0.13678
server, stratum 2, offset 116.851198, delay 0.13593
server, stratum 3, offset 116.854724, delay 0.06856
rver, stratum 3, offset 116.850088, delay 0.11681
server, stratum 2, offset 116.853743, delay 0.08235
server, stratum 3, offset 116.853282, delay 0.13957
server, stratum 2, offset 116.850962, delay 0.11897
server, stratum 3, offset 116.854568, delay 0.04176
server, stratum 2, offset 116.857820, delay 0.14392
server, stratum 2, offset 116.852686, delay 0.14960
server, stratum 2, offset 116.856700, delay 0.07793
server, stratum 2, offset 116.851880, delay 0.10410
server, stratum 2, offset 116.855086, delay 0.13277
server, stratum 1, offset 116.847096, delay 0.26810
21 Sep 07:18:33 ntpdate[8019]: step time server offset 116.847096 sec

The offset indicates that my clock is slow by 116 seconds, or a tad under two minutes. That's not too bad, because it took me three months to read Anna Karenina. Nevertheless, two seconds is a lot in networking, so we should rectify this situation.

NTP for Control Freaks

Personally, I'm suspicious of background processes. I don't like "services" and "daemons" running on my computer, because I just don't know what they're doing when I'm not paying attention. In fact, if I had my way, I'd turn off the autonomous signaling on my spinal cord and control my own breathing. That's why I like to synchronize my clock whenever I feel like it with the ntpdate command we used before, but without the q option.

>sudo ntpdate pool.ntp.org
21 Sep 06:55:50 ntpdate[6512]: step time server offset 116.841196 sec

This changed my clock forward 116.8 seconds. Since this is a one-time update, the computer's clock will eventually drift.

NTP for Couch Potatoes

Most people are, unlike me, normal, and they would rather have the computer automatically update its clock against an NTP server. To do this, you need to install the NTP daemon. On Ubuntu, use the following command:

>sudo apt-get install ntp

During the installation, the following prompt appears:

Configuration file `/etc/ntp.conf'
==> File on system created by you or by a script.
==> File also in package provided by package maintainer.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : background this process to examine the situation
The default action is to keep your current version.
*** ntp.conf (Y/I/N/O/D/Z) [default=N] ?

Press N to keep the current version, and we'll configure it later.

Let's run the time utility on Ubuntu:

>sudo time-admin

Click Select Servers and locate the server of your choice. Selecting more than one server will give your computer a more accurate time, but selecting too many will clog your network connection.

If you want to go back to manual updates, select Manual from the Configuration list.

In this case, you're back to manually updating the clock by yourself or through a one-time synchronization with an NTP server.

That's all for clock synchronization on Ubuntu.

Thanks for checking in at the Tool Bar & Grill. Come back often for hot tips on the best free and cheap software and useful Web sites, and now for related Linux recommendations too! Feel free to comment below or write to jonathanstoolbar@gmail.com.

1 comment:

  1. Thanks for the useful information. But, can I use the WinPST in Linux?
    . I am using it in windows xp to share outlook data with my colleagues.