Tuesday, October 5, 2010

ntp update clock

Hi all.

In this post, I explain how to update the time with ntpdate command in bash shell.

I have written the shell script to test if your Linux OS is Ubuntu or a Fedora and then execute the appropriate command to install ntp and sync your clock with an ntp server.

  • If you are a fedora user, you need to first add yourself to the sudoer's list before executing this shell script.

In order to add yourself to the sudoer list, you do the following:

  • execute the command "su" in terminal to login as root, give the username and password to login.

  • After you follow the above step, execute the command "visudo" and press "i".
  • Then you browse through the terminal (by up or down key) to find the text "root    ALL=(ALL)    ALL". 
  • Then below the line you add: "    ALL=(ALL)    ALL" like in "rahul    ALL=(ALL)    ALL" in the same format as in for "root    ALL=(ALL)    ALL". 
  • Press ":" (shift semicolon) and enter "wq" and press enter key.


All you are doing is entering the visudo and adding yourself to the sudoers list and saving the file in (vi command mode).

Now your user is capable of executing sudo commands (like an install command).

Ubuntu users need not do the above mentioned steps.

Now write the following commands in a .sh file (say ntpexecute.sh) and save it.


Now run the program by typing ./ntpexecute.sh

1 comment:

  1. You can also use the following commands in the script for more functionality (and also if your system says "ntp socket in use" which means already a ntp daemon is running).

    sudo /etc/init.d/ntp stop
    sudo /etc/init.d/ntp start

    ReplyDelete