From 3b524772214090829493837e00423635ce29c59c Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 24 Aug 2014 00:54:34 +0200 Subject: sup: add options Signed-off-by: Florian Pritz --- sup | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) (limited to 'sup') diff --git a/sup b/sup index 3ec84f5..c6cb304 100755 --- a/sup +++ b/sup @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # delay starting after 2 failed runs delay_after=2 @@ -7,7 +7,6 @@ delay_reset_after=60 # delay for 30 seconds delay=30 -command="$*" times_ran=0 cleanup() { @@ -20,6 +19,58 @@ cleanup() { trap cleanup 2 15 +while :; do + case $1 in + --delay) + if [[ ! $2 ]]; then + echo "Missing argument to --delay" >&2 + exit 1 + fi + + delay=$2 + shift 2 + continue + ;; + --reset-after) + if [[ ! $2 ]]; then + echo "Missing argument to --reset-after" >&2 + exit 1 + fi + + delay_reset_after=$2 + shift 2 + continue + ;; + --delay-after) + if [[ ! $2 ]]; then + echo "Missing argument to --delay-after" >&2 + exit 1 + fi + + delay_after=$2 + shift 2 + continue + ;; + --help|-h) + echo "usage: ${0##*/} [options] [--] " + echo '' + echo 'Options:' + echo ' --help, -h this help' + echo ' --delay amount of delay after enoguh failed runs' + echo ' --delay-after amount of runs after which we wait' + echo ' --reset-after reset the failed counter after this time' + exit 0 + ;; + --|*) + shift + break + ;; + esac + shift +done + +command=("$@") + while :; do times_ran=$(($times_ran+1)) if [ $times_ran -gt $delay_after ]; then @@ -30,7 +81,7 @@ while :; do time_started=`date +%s` echo -n "running... " >&2 - $command & + ${command[@]} & pid=$! echo PID: $pid >&2 wait $pid -- cgit v1.2.3-24-g4f1b