:
##########################################################################
# Shellscript:	periodic - periodically execute command
# Author     :	Heiner Steven <heiner.steven@odn.de>
# Date       :	1995-03-03
# SCCS-Id.   :	@(#) periodic	1.2 03/03/18
##########################################################################
# Description
#
##########################################################################

PN=`basename "$0"`			# program name
VER='1.2'

DefInterval=5

Usage () {
    echo >&2 "$PN - periodically execute command, $VER
usage: $PN [-t seconds] command [argument ...]
    -t:  interval length (in seconds, default is $DefInterval s)"
    exit 1
}

# We should use "getopts" here because it preserves whitespace.
# On the other hand very old shells do not have the command.
#set -- `getopt t:h "$@"`
while [ $# -gt 0 ]
do
    case "$1" in
	-t)	Interval="$2"; shift;;
	--)	shift; break;;
	-h)	Usage;;
	-*)	Usage;;
	*)	break;;			# Command name
    esac
    shift
done

[ $# -lt 1 ] && Usage

eval "$@"
while sleep ${Interval:=$DefInterval}
do
    eval "$@"
done
