On Fri, Jun 01, 2012 at 03:47:21PM +1000, David Diggles wrote:
[ snip ]
>     sleep $s
[ snip ]

Arghh.. ;-) sleep $seconds here

Anyway, you get the idea.

#!/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
}

Reply via email to