Unix Technical Forum

Synchronize system clock?

This is a discussion on Synchronize system clock? within the Slackware Linux Support forums, part of the Unix Operating Systems category; --> Hi, Is there a simple way to synchronize my system clock, say, on startup? My laptop unfortunately has a ...


Go Back   Unix Technical Forum > Unix Operating Systems > Slackware Linux Support

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-20-2008, 07:21 PM
Niki Kovacs
 
Posts: n/a
Default Synchronize system clock?

Hi,

Is there a simple way to synchronize my system clock, say, on startup? My
laptop unfortunately has a broken battery, and everytime I disconnect the
power cable, the clock freezes... only to resume activity at the next
boot... which always makes me travel back in time )

Cheers,

Niki
--
Whereof one cannot speak, thereof one frequently goes ranting on and on
at ball-breaking length. -- Ludwig Wittgenstein, Tractatus logico-
philosophicus, first draft.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-20-2008, 07:21 PM
Ivan Rajkovic
 
Posts: n/a
Default Re: Synchronize system clock?

On Fri, 15 Dec 2006 11:59:10 +0100, Niki Kovacs wrote:

> Hi,
>
> Is there a simple way to synchronize my system clock, say, on startup? My
> laptop unfortunately has a broken battery, and everytime I disconnect the
> power cable, the clock freezes... only to resume activity at the next
> boot... which always makes me travel back in time )
>
> Cheers,
>
> Niki


put this is /etc/rc.d/rc.local :

/usr/sbin/ntpdate de.pool.ntp.org
/sbin/hwclock -w

you can change ntp server, here is the list:
http://ntp.isc.org/bin/view/Servers/WebHome

--
i.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-20-2008, 07:21 PM
del
 
Posts: n/a
Default Re: Synchronize system clock?

Thelonious Monk lived in an eleven-dimensional house.
On Saturday 16 Dec 2006 15:28 Ivan Rajkovic, wrote:

> On Fri, 15 Dec 2006 11:59:10 +0100, Niki Kovacs wrote:
>
>> Hi,
>>
>> Is there a simple way to synchronize my system clock, say, on
>> startup?

>
> put this is /etc/rc.d/rc.local :
>
> /usr/sbin/ntpdate de.pool.ntp.org
> /sbin/hwclock -w


Does this set the clock? I thought it needed "-s" to set.
e.g. /usr/sbin/ntpdate -s de.pool.ntp.org

--
del 8-)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-20-2008, 07:21 PM
Niki Kovacs
 
Posts: n/a
Default Re: Synchronize system clock?

Le Sat, 16 Dec 2006 16:28:39 +0100, Ivan Rajkovic a écrit*:

> put this is /etc/rc.d/rc.local :
>
> /usr/sbin/ntpdate de.pool.ntp.org
> /sbin/hwclock -w


Thanks very much! Worked like a charm!

Niki
--
Whereof one cannot speak, thereof one frequently goes ranting on and on
at ball-breaking length. -- Ludwig Wittgenstein, Tractatus logico-
philosophicus, first draft.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-20-2008, 07:21 PM
Douglas Mayne
 
Posts: n/a
Default Re: Synchronize system clock?

On Fri, 15 Dec 2006 11:59:10 +0100, Niki Kovacs wrote:

> Hi,
>
> Is there a simple way to synchronize my system clock, say, on startup? My
> laptop unfortunately has a broken battery, and everytime I disconnect the
> power cable, the clock freezes... only to resume activity at the next
> boot... which always makes me travel back in time )
>
> Cheers,
>
> Niki
>

Some dhcpd servers send the ntp clock information. The script below does
some simple parsing to get the name of the server. Make the script
executable and add a section in rc.local to start rc.ntpd if it is
executable.

#!/bin/bash
#
# file: /etc/rc.d/rc.ntpd
# http://www.gnu.org/licenses/gpl.txt
# Douglas D. Mayne (c) 2006
#
NTPDATE=$(which ntpdate)
NTPD=$(which ntpd)
preferred_clock() {
cat /etc/ntp.conf | grep -v "^#" | grep -v 127\. \
| grep "^server " | head -1 | sed 's/^server //'
}
set_clock() {
CLOCK=$(preferred_clock)
echo Preferred Clock is $CLOCK
[ ! -x $NTPDATE ] && exit 1
ping -c 1 $CLOCK || exit 1
killall ntpd
sleep 4
echo "Setting the clock..."
$NTPDATE -b $CLOCK
sleep 2
}
case "$1" in
'start')
set_clock && $NTPD
;;
'stop')
killall ntpd
;;
'status')
ntpq -c peers
;;
*)
echo "usage $0 start|stop|status"
esac
# end rc.ntpd

--
Douglas Mayne




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-20-2008, 07:21 PM
notbob
 
Posts: n/a
Default Re: Synchronize system clock?

On 2006-12-16, Niki Kovacs <mickey@mouse.com> wrote:

>> /usr/sbin/ntpdate de.pool.ntp.org
>> /sbin/hwclock -w

>
> Thanks very much! Worked like a charm!


Now, put it in one of your crons and you'll never be more than a
couple nanoseconds off time.

nb
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-20-2008, 07:21 PM
=?ISO-8859-15?Q?J=E9r=F4me?= PRIOR
 
Posts: n/a
Default Re: Synchronize system clock?

> Thelonious Monk lived in an eleven-dimensional house.
> On Saturday 16 Dec 2006 15:28 Ivan Rajkovic, wrote:
>
> > On Fri, 15 Dec 2006 11:59:10 +0100, Niki Kovacs wrote:
> >
> >> Hi,
> >>
> >> Is there a simple way to synchronize my system clock, say, on
> >> startup?

> >
> > put this is /etc/rc.d/rc.local :
> >
> > /usr/sbin/ntpdate de.pool.ntp.org
> > /sbin/hwclock -w

>
> Does this set the clock? I thought it needed "-s" to set.
> e.g. /usr/sbin/ntpdate -s de.pool.ntp.org
>


no it works fine without -s ... why there is no man/info pages ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-20-2008, 07:21 PM
=?ISO-8859-15?Q?J=E9r=F4me?= PRIOR
 
Posts: n/a
Default Re: Synchronize system clock?

> On 2006-12-16, Niki Kovacs <mickey@mouse.com> wrote:
>
> >> /usr/sbin/ntpdate de.pool.ntp.org
> >> /sbin/hwclock -w

> >
> > Thanks very much! Worked like a charm!

>
> Now, put it in one of your crons and you'll never be more than a
> couple nanoseconds off time.
>
> nb


hoo my god /o\

you'll never put that in cron !!! What append if, a the same
millisecond, all the billion of pc go and connect to ntpd server ?

Read the online doc, I ve got ressource in french if you want. It is
better to run ntpd instead of using ntpudate in crontab job.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-20-2008, 07:21 PM
james
 
Posts: n/a
Default Re: Synchronize system clock?

notbob <notbob@nothome.com> wrote in news:gdudneqZY-
1VghnYnZ2dnUVZ_qWdnZ2d@comcast.com:

> On 2006-12-16, Niki Kovacs <mickey@mouse.com> wrote:
> Now, put it in one of your crons and you'll never be more than a
> couple nanoseconds off time.


For clarity's sake, the "it" above is ntpdate.

I wrote an rc.ntpd with status|start|stop|restart with logging and a
logrotate configuration. I posted it for comment to the Slackware forum of
http://www.linuxquestions.org. There was some feedback with suggestions.
http://www.linuxquestions.org/questi...d.php?t=471465
should take you right to it (if you're interested, of course).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-20-2008, 07:21 PM
rm@biteme.org
 
Posts: n/a
Default Re: Synchronize system clock?

Ivan Rajkovic <ivan@iep.physik.uni-essen.de> wrote:
> On Fri, 15 Dec 2006 11:59:10 +0100, Niki Kovacs wrote:
>
>> Hi,
>>
>> Is there a simple way to synchronize my system clock, say, on startup? My
>> laptop unfortunately has a broken battery, and everytime I disconnect the
>> power cable, the clock freezes... only to resume activity at the next
>> boot... which always makes me travel back in time )
>>
>> Cheers,
>>
>> Niki

>
> put this is /etc/rc.d/rc.local :
>
> /usr/sbin/ntpdate de.pool.ntp.org
> /sbin/hwclock -w
>
> you can change ntp server, here is the list:
> http://ntp.isc.org/bin/view/Servers/WebHome


We still use rdate. We include the following in rc.local:

/usr/bin/rdate -s 129.6.15.29

Is there a reason to use ntpd over rdate?

cordially, as always,

rm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:20 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com