Quickly sync/update time from a time server

by jagbir on February 5, 2009

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.

  • http://www.uddtm.com Linux Top10 tips

    learn!

  • Mike

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

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

  • http://xeon.dhis.org Xeon Project

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

    /sbin/hwclock –systohc

  • http://linuxadminzone.com jagbir

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

  • k

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

  • http://linuxadminzone.com jagbir

    Thanks k for pointing out the typo. corrected.

  • Pingback: Blog trao doi kien thuc ve Hosting

  • Pingback: ROV Courses

  • http://freeldssheetmusic.org roger

    ntpdate[3619]: no server suitable for synchronization found

Previous post:

Next post: