Home > Unix > How to synchronize clock with NTP server

How to synchronize clock with NTP server

Basically ntpdate command synchronize the clock with specified ntp server. To synchronize the clock with ntp server all the time when you start your machine do the followings.

First Create a file named setdate with any editor and write the following line in the file

  #!/bin/bash
case "$1" in
start)
ntpdate sol(ntp server)
;;
stop)
;;
esac
exit 0

copy the file(setdate) by the following command to the location /etc/init.d/

    # cp setdate /etc/init.d/setdate
    # chmod 751 /etc/init.d/setdate

Now create startup scripts to sync the time during system boot.

    # update-rc.d setdate defaults

Also run tzselect to define time change(super user/normal user), Change timezone in /etc/timezone file and put the following line in /etc/bash.bashrc file, user’s .bashrc’ and .bash_profile file which user you want to get syncronized

    TZ='Asia/Dhaka'; export TZ;

Reboot your machine to get effects.

Categories: Unix
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s