Ok;

After running that a few days, it works fine, but... the interval between 
updates
is all over the place.

I rewrote it, to only change the sleep value under 2 circumstances:

First time run, or after a failure.

Now it's updating hourly again.

I will not make the same mistake of posting it to the list, because archiving a
possibly buggy script that someone may copy someday is not a great idea.

However I think the methodology is now sound, so write your own or mail me 
directly
if you want a copy of it to adopt.

On Fri, Jun 01, 2012 at 04:45:24PM +1000, David Diggles wrote:
> > #!/bin/sh
> > remaining=$1;shift
> > cmd=$@
> > lock=/var/run/$(basename $1).lock
> > [ -f $lock ] || {
> >   touch $lock
> >   while [ $remaining -gt 0 ]; do
> >     seconds=$(($RANDOM % $remaining))
> >     echo $(date) $seconds >> $lock
> >     sleep $seconds
> >     $cmd && return || remaining=$(($remaining - $seconds))
> >   done
> >   rm $lock
> > }
> > 
> 
> *groan*.. another mistake.. I'm such an idiot sometimes ;-)
> 
> I don't recommend running this without checking it first.
> 
> #!/bin/sh
> remaining=$1;shift
> cmd=$@
> lock=/var/run/$(basename $1).lock
> [ -f $lock ] || {
>   touch $lock
>   while [ $remaining -gt 0 ]; do
>     seconds=$(($RANDOM % $remaining))
>     echo $(date) $seconds >> $lock
>     sleep $seconds
>     $cmd && break || remaining=$(($remaining - $seconds))
>   done
>   rm $lock
> }

Reply via email to