Jump to content

Setting time from the command line


liquidzoo
 Share

Recommended Posts

I got this command from illogic-al tonight on IRC and thought I would share it with you. I made myself a small script that will do it automatically.

 

The command is rdate. First off, make sure rdate is installed by issuing the following command as root:

 

urpmi rdate

 

Then fire up your favorite text editor and paste in the following line of text:

 

su -c 'rdate -p -s clock.psu.edu'

 

Save that as whatever you want, just remember the filename. In my case, it is time.sh

 

Open up a console and change to wherever you saved the script and issue the following command, substituting in your filename for my time.sh:

 

chmod +x time.sh

 

After that, when you want to make sure your time is correct, and set it if not; open a terminal and change to where you saved your script. Once there, issue

 

./time.sh

 

Once again, substituting your filename for mine. It will prompt you for your root password (this is so it has access to change the system time, it will only be for one command). Once you have entered your root password, it will print the time in your timezone from the clock.psu.edu server and set the system time if yours is off.

 

You can substitute your favorite time server for the clock.psu.edu if you would like.

 

Enjoy!

 

EDIT to correct the command. It wasn't working on my system the way I had typed it.

Link to comment
Share on other sites

Actually, rdate sets time received from a network host, in this example the romte host is clock.psu.edu. You can update time automatically by adding something like this to root's crontab file

 5 1 * * * rdate -s your.trusted.network.host

This will make your computer to syncronise with the remote host every day (night, hour, etc) without you having to run any scripts (and type in the root password).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...