Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a VPS running on Cent Os 5.8 (x86). There are situations in which we are forced to reset the entire VPS (it hangs and the only way to get it back on is to reset it). When we do so, the time is reset too.

We use the following command to set the time (the timezone is configured through kloxo admin panel and is not reset like the time does):

#date +%T%p -s "10:10:10" (as for hour 10 and minutes 10 and seconds 10 )
share|improve this question
    
You have no choice but to tolerate the lockups? I would be hammering on the VPS providers door for answers. –  Tim Aug 21 '12 at 17:36
    
Are you hard coding 10:10:10 every time or is that an example? Are you trying to pull real time values? –  Tim Aug 21 '12 at 17:37
    
Can't you use NTP? –  cjc Aug 21 '12 at 17:51
    
@Tim:Well he is not answering and keeps saying the vps is completely unmanned and its all on us. And at the moment yes, because i couldn't have found the cause(s) so far.(i will open another question for solving this question later) that 10:10:10 is just an example of my input.My local timezone is Iran/Tehran, the timezone is set , for setting the time, i sync it with my pcs current time.Im trying to set the time not getting it( if i got your meaning by 'pulling the time' right) –  Hossein Aug 21 '12 at 18:30
    
@cjc:What is NTP? i have no idea what that is.I am just a simple linux user(newbie) –  Hossein Aug 21 '12 at 18:30
add comment

2 Answers

up vote 5 down vote accepted

You can use NTP (Network Time Protocol) if this machine is Internet connected. This will synchronize the machine's clock to an Internet time server.

yum install ntp, then edit the /etc/ntp.conf file so that you have at least one line that looks like:

server 0.pool.ntp.org

Then chkconfig ntpd on so that it will start up automatically on boot.

Once this is done, start the NTP service with service ntpd start or /etc/init.d/ntpd start.

Here's some additional documentation from Slicehost.

share|improve this answer
    
It still says 7:13 while it should say 11:13PM,are there any other options which i should mess around with? –  Hossein Aug 21 '12 at 18:44
    
@Hossein That's a timezone issue. Look at redhat.com/advice/tips/timezone.html –  cjc Aug 21 '12 at 18:47
    
I just noticed everything is fine:),I guess that was a browser cache issue and not the servers itself;) it is set to 12:22PM as it should have :) –  Hossein Aug 21 '12 at 19:52
add comment

The program date sets the system clock, i.e. the clock maintained internally by the operating system. There is a separate clock inside the computer which keeps the time when the computer is off (or rebooting). If you've set the system clock manually, call hwclock to set the hardware clock as well.

hwclock --utc --systohc

(Replace --utc by --localtime if your hardware clock is set to local time. This should only be done if you dual boot with Windows.)

Some distributions have a script that calls hwclock with the right options (--utc or --localtime, and if relevant other hardware-specific options). For example, on Debian, run /etc/init.d/hwclock.sh stop. I don't know about CentOS.

All of this is for a one-time thing. If your computer has a permanent or frequent Internet connection, once you've set the time approximately right manually, make it synchronize its time over the network, using NTP. See cjc's answer.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.