LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-04-2013, 11:43 AM   #1
T-Dub116
Member
 
Registered: Aug 2013
Location: Dolyestown
Posts: 88

Rep: Reputation: Disabled
Setting Software clock to Match Hardware clock


Linux Redhat:

when my system is running harder usually during backups and what not, the time will slowdown with it and I have to keep changing it in order for it to stay accurate.

How can I set the Software clock to match the Hardware clock so that it is always correct?

something in Cron maybe...

Last edited by T-Dub116; 12-04-2013 at 11:57 AM.
 
Old 12-04-2013, 11:49 AM   #2
DavidMcCann
Senior Member
 
Registered: Jul 2006
Location: London
Distribution: CentOS, Salix
Posts: 4,703

Rep: Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497Reputation: 1497
You could always set the computer to use the Network Time Protocol: regularly check on the internet.
 
Old 12-04-2013, 11:58 AM   #3
T-Dub116
Member
 
Registered: Aug 2013
Location: Dolyestown
Posts: 88

Original Poster
Rep: Reputation: Disabled
The time is Wed 12/4 11:57am and here is what the server says

# date
Wed Dec 4 11:33:40 EST 2013
# hwclock
Wed 04 Dec 2013 01:00:49 PM EST -0.016045 seconds

How do I edit the HW clock to be the right time and then have the software clock look at the HWclock...something like,

/sbin/hwclock --hctosys

Last edited by T-Dub116; 12-04-2013 at 12:01 PM.
 
Old 12-04-2013, 01:02 PM   #4
Z038
Member
 
Registered: Jan 2006
Distribution: Slackware
Posts: 841

Rep: Reputation: 165Reputation: 165
I do it the other way around, usually, by synching the system clock to the nist time server, then set the hwclock from that:

Code:
# ntpdate time.nist.gov
# hwclock --systohc --utc
I think it gives me a more accurate time. But you could do it as you've specified like this:

Code:
# hwclock --set --date="2013-12-04 12:02:00"
# hwclock --hctosys
The above example of --set with --date is in the man page for hwclock.

Last edited by Z038; 12-04-2013 at 01:27 PM.
 
1 members found this post helpful.
Old 12-04-2013, 02:02 PM   #5
T-Dub116
Member
 
Registered: Aug 2013
Location: Dolyestown
Posts: 88

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Z038 View Post
I do it the other way around, usually, by synching the system clock to the nist time server, then set the hwclock from that:

Code:
# ntpdate time.nist.gov
# hwclock --systohc --utc
I think it gives me a more accurate time. But you could do it as you've specified like this:

Code:
# hwclock --set --date="2013-12-04 12:02:00"
# hwclock --hctosys
The above example of --set with --date is in the man page for hwclock.


If you do it the other way around, show me what you do for that...
 
Old 12-05-2013, 02:30 AM   #6
Z038
Member
 
Registered: Jan 2006
Distribution: Slackware
Posts: 841

Rep: Reputation: 165Reputation: 165
I showed that already. It's the first code block in my previous post. I issue the ntpdate command to set the software clock from an internet time server, then issue the hwclock command to set the hardware clock from the system clock.

I have an ancient laptop with a bad battery that always loses the hardware clock setting when it is shutdown. I put those commands in a shell script and run it out of /etc/rc.local to reset the hardware clock whenever I boot. You could make an entry for it in root's crontab and run it as often as you like.

Code:
#!/bin/bash
ntpdate pool.ntp.org
hwclock --systohc --utc
By the way, the general recommendation (in the US) is to sync to pool.ntp.org rather than to time.nist.gov in order to reduce the demand on the NIST server.



Another thing you could do is set up an ntp server on some system on your local network, then have all your other systems sync to it.

Last edited by Z038; 12-05-2013 at 02:35 AM.
 
1 members found this post helpful.
Old 12-05-2013, 09:08 AM   #7
T-Dub116
Member
 
Registered: Aug 2013
Location: Dolyestown
Posts: 88

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Z038 View Post
I showed that already. It's the first code block in my previous post. I issue the ntpdate command to set the software clock from an internet time server, then issue the hwclock command to set the hardware clock from the system clock.

I have an ancient laptop with a bad battery that always loses the hardware clock setting when it is shutdown. I put those commands in a shell script and run it out of /etc/rc.local to reset the hardware clock whenever I boot. You could make an entry for it in root's crontab and run it as often as you like.

Code:
#!/bin/bash
ntpdate pool.ntp.org
hwclock --systohc --utc
By the way, the general recommendation (in the US) is to sync to pool.ntp.org rather than to time.nist.gov in order to reduce the demand on the NIST server.



Another thing you could do is set up an ntp server on some system on your local network, then have all your other systems sync to it.

What do you think about this?

I set the date time (system Time)

date +%T -s 08:00:00 #8 am for an example

Then do: hwclock -w # to match the hwclock with the date clock

Then put this in crontab to keep them in sync

45 22,01,02 * * * /sbin/hwclock --hctosys


.
 
Old 12-05-2013, 01:08 PM   #8
Z038
Member
 
Registered: Jan 2006
Distribution: Slackware
Posts: 841

Rep: Reputation: 165Reputation: 165
Yes, that will work. However, the time value you set manually that way is not likely to be as accurate as what you would get from an ntp server. So if your server is connected to the internet or if you have an ntp server on your network that you can sync to, you could get a much more accurate time.

You don't need to specify +%T on the date command. That controls the output format of the date. It doesn't have any bearing on the -s date string input value.

Last edited by Z038; 12-05-2013 at 06:59 PM.
 
Old 12-06-2013, 09:28 AM   #9
T-Dub116
Member
 
Registered: Aug 2013
Location: Dolyestown
Posts: 88

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Z038 View Post
Yes, that will work. However, the time value you set manually that way is not likely to be as accurate as what you would get from an ntp server. So if your server is connected to the internet or if you have an ntp server on your network that you can sync to, you could get a much more accurate time.

You don't need to specify +%T on the date command. That controls the output format of the date. It doesn't have any bearing on the -s date string input value.

The Server is connected to the Internet, I don't believe they have a ntp server. What would you recommend being that the server does connect to the internet?
 
Old 12-06-2013, 08:08 PM   #10
Z038
Member
 
Registered: Jan 2006
Distribution: Slackware
Posts: 841

Rep: Reputation: 165Reputation: 165
I would do what I described above in post #6 at boot up and at least once per day via cron to ensure the hardware clock stays fairly accurate. Then periodically throughout the day I would have cron run just the ntpdate command to reset the system clock from an internet time source (e.g., pool.ntp.org). How often you should run ntpdate depends on how fast your system clock gets out of sync. There's no problem with running it once an hour or even every five minutes.

Alternatively, if your hardware clock stays pretty accurate and you want to keep the system clock in sync with it, but you don't need to synchronize with the outside world, then you could use cron to periodically issue the hwclock --hctosys command as often as you need to keep them in sync.

The most automatic way of keeping the system clock accurate is to run the ntpd service (daemon). It's not that hard to set up, and it will keep your system clock synchronized with the internet ntp time servers.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why system clock runs faster than hardware clock? DavidLiu Linux - Software 2 01-23-2011 08:38 AM
System clock correct, hardware clock wrong karlovac Linux - General 5 01-16-2009 08:19 PM
Failed to set system clock to hardware clock jrtayloriv Linux - Newbie 2 09-25-2008 08:06 AM
Slow system clock and stray hardware clock, pleas help! Epox Linux - General 6 01-02-2007 03:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration