Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 1 Feb 2005 10:20:24 -0800 (PST)
From:      Julian Elischer <julian@elischer.org>
To:        current@freebsd.org
Subject:   cynchronised sleep capbilty..
Message-ID:  <20050201101113.J572@localhost>

next in thread | raw e-mail | index | archive | help

I often find myself wanting to write shell scripts that do:

while :
do
 	{report some statistic}
 	sleep 10
done


now this is of course only approximate as the delay will not be
exactly 10 seconds and it will gradually creep..

This doesn't matter too much except that I now need to do
the same on 50 machines and I need the data to line up.

The machiens all have ntp running so their clocks are
all alligned (enough)
so what I really need is:


while:
do
 	report results
 	sleep -until_next 10
done


I have inplemented something like this with a crude
shell function that sleeps up to 9 seconds to get to
thenext N+9 second, and then loops with sleep 0.1
up to 10 times until the second ticks over, but that
is a hack and inneficient to say the least..

firstly: does anyone know a better way to do this?

secondly: is it worth implementing some
   "do ths every N seconds" facility somewhere?
   e.g. sleep -u 10  # sleep until next 10 second boundary.

thirdly: is it worth making sleep a shell builtin?
running sleep(1) every time is a lot of work for what
we need.

julian




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050201101113.J572>