Quickly sync/update time from a time server

A good server machine should always tick its clock with correct time. The best way to keep it in shape is to sync with a time server.

You can use any preferred time server to sync. I’m using public time servers here:

$ ntpdate pool.ntp.org
5 Feb 11:17:00 ntpdate[3332]: step time server 220.225.252.202 offset -585.969659 sec

Network time update command (ntpdate) will contact the available time server from public pool and sync time with it. Here in above example, offset is denoting that the clock was running ahead of time in my server.

To remain updated, you should put a cron entry to sync with time server every midnight:

$ crontab -e
0 4 * * * /usr/sbin/ntpdate pool.ntp.org

This will update/correct your time in server at 04:00 am every morning. I’ve written a very quick trick to correct your time. If you are interested to study further, you can find detailed information here.

8 Responses to “Quickly sync/update time from a time server”

  1. learn!

  2. Error in your command, you have 1 to many *.

    crontab -e 0 4 * * * /usr/sbin/ntpdate pool.ntp.org

  3. nice code. but to after that it is also important to set hwclock . do this with this code:

    /sbin/hwclock –systohc

  4. Thanks Xeon and Mike for comments, I will check further and improve code.

  5. i think 0 4 * * * cronjob would happen at 4am not 00:04am

  6. Thanks k for pointing out the typo. corrected.

  7. Blog trao doi kien thuc ve Hosting…

    [...]Quickly sync/update time from a time server | Linux Admin Zone[...]…

  8. Stop Now…

    Please don’t force me to read that story ever again have mercy….

Leave a Reply

Notify me of followup comments via e-mail. You can also subscribe without commenting.