Istvan Gabor said the following on 02/19/2011 07:12 AM:
Hello:
My system clock tends to stray (1-2 minutes within a week, or so) So far I adjusted the time manually using the command: # sntp -r ntp1.ptb.de then setting hwclock # hwclcok --systohc
I would like the system automatically set/keep the time. I also discovered that there is no /etc/adjtime on my system. Is that normal?
Where could I find a decent description on how to use 1) adjtime method for keeping time, or 2) sntp in case when the system is turned off and on frequently and is connected to the net occasionally only.
The obvious answer to "where" is "have you googled?" But a more practical answer starts with "how have you set up date and time with YAST?" I see a setting for turning NTP on and configuring it. Start with yast -> system -> date and time You get a graphic of a map; set your timezone. Bottom right it says whether NTP is configured or not. Click the "Change" button. You get a new dialogue box "Change Date And time" There you can set the NTP service. If you run the daemon then it should start on each boot (or you could do some /etc/rc???? stuff to do a NTP one off on boot) and keep your clock synchronised. The "configure" button lets you set up the NTP daemon with alternate time servers. You may have to google to find some alternative time servers. If you don't like any of that you can run sntp from cron, or better, 'ntpd -q' Since I run ntpd I don't worry about the hardware clock. So long as I have a network connection, boot will run ntpd of some form and set the system clock, and its the system clock that matters. If I don't have a connection, yes it all falls back to the hardware clock, but so long as that isn't WAY out I have to face the priority of not having a network connection for my laptop. If I loose a connection for my 'desktop' during the day, then MAYBE the clock will drift, but that is a lesser problem than the loss of the connection! The other part of your question - adjtime - presupposes that you are reliant SOLELY on the hardware clock. If you read the manual page for HWCLOCK it says <quote> The Adjust Function The Hardware Clock is usually not very accurate. However, much of its inaccuracy is completely predictable - it gains or loses the same amount of time every day. This is called systematic drift. hwclock's "adjust" function lets you make systematic corrections to correct the systematic drift. It works like this: hwclock keeps a file, /etc/adjtime, that keeps some historical information. This is called the adjtime file. Suppose you start with no adjtime file. You issue a hwclock --set command to set the Hardware Clock to the true current time. Hwclock creates the adjtime file and records in it the current time as the last time the clock was calibrated. 5 days later, the clock has gained 10 seconds, so you issue another hwclock --set command to set it back 10 seconds. Hwclock updates the adjtime file to show the current time as the last time the clock was calibrated, and records 2 seconds per day as the systematic drift rate. 24 hours go by, and then you issue a hwclock --adjust command. Hwclock consults the adjtime file and sees that the clock gains 2 seconds per day when left alone and that it has been left alone for exactly one day. So it subtracts 2 seconds from the Hardware Clock. It then records the current time as the last time the clock was adjusted. Another 24 hours goes by and you issue another hwclock --adjust. Hwclock does the same thing: subtracts 2 seconds and updates the adjtime file with the current time as the last time the clock was adjusted. Every time you calibrate (set) the clock (using --set or --systohc), hwclock recalculates the systematic drift rate based on how long it has been since the last calibration, how long it has been since the last adjustment, what drift rate was assumed in any intervening adjustments, and the amount by which the clock is presently off. </quote> That seems pretty clear to me. Of course its totally irrelevant to me since I use the ntp daemon. I could probably get by if my hwclock battery ran out :-) Mind you /etc/cron.daily/suse.de-check-battery should tell me if my battery is running low or dead. <quote src="man page for hwclock"> Automatic Hardware Clock Synchronization By the Kernel You should be aware of another way that the Hardware Clock is kept synchronized in some systems. The Linux kernel has a mode wherein it copies the System Time to the Hardware Clock every 11 minutes. This is a good mode to use when you are using something sophisticated like ntp to keep your System Time synchronized. This mode (we'll call it "11 minute mode") is off until something turns it on. The ntp daemon xntpd is one thing that turns it on. You can turn it off by running anything, including hwclock --hctosys, that sets the System Time the old fashioned way. To see if it is on or off, use the command adjtimex --print and look at the value of "status". If the "64" bit of this number (expressed in binary) equal to 0, 11 minute mode is on. Otherwise, it is off. If your system runs with 11 minute mode on, don't use hwclock --adjust or hwclock --hctosys. You'll just make a mess. It is acceptable to use a ' hwclock --hctosys at startup time to get a reasonable System Time until your system is able to set the System Time from the external source and start 11 minute mode. </quote> Since I'm running ntp (and it doesn't matter if its daemon or "-q" from cron) the "11 minute mode" applies and I don't have to worry about syncing system to hardware "manually". Automatic is nice. But then there is one other thing that matters in all this. What are the settings in your /etc/fstab? Many people, especially those with laptops, mount files systems with noatime,nodiratime to reduce the disk activity. If you're not updating the access times than the clock doesn't matter, does it? So, the answer to your question "I would like the system automatically set/keep the time" is "Use NTP in daemon or '-q' mode" That also deals with the situation I have with my laptop where its turned on and of frequently. The "connected to the net occasionally only" is not going be a hurdle so long as there is connection often enough. You should establish how much clock drift you can tolerate. A server supplying a service to many people and having legal and contractual obligations will be more demanding than a netbook used for recording notes in a rain-forest or a desert, away from normal contact. But then that server will also have a reliable connection to fulfil those terms of service. One other factor is 'anacron'. (go google) It can be set up to ensure that cron jobs with a small periodicity are not missed on systems that are not up continuously. This is an excellent way to ensure that 'ntpd -q' is run. Try http://www.ibm.com/developerworks/linux/library/l-anacron/?ca=dgr-lnxw06Anacron&S_TACT=105AGX59&S_CMP=grlnxw06 That being said, the openSuse version of cron supports notation like @reboot : Run once, at startup. which isn't the same thing, but in this context will suffice to make sure 'ntpd -q' is run at startup. -- Almost all quality improvement comes via simplification of design,manufacturing, layout, processes, and procedures. -- Tom Peters -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org