diff options
author | Florian Pritz <bluewind@xinu.at> | 2014-08-24 00:54:34 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2014-08-24 00:54:34 +0200 |
commit | 3b524772214090829493837e00423635ce29c59c (patch) | |
tree | b0419f25d6f82269fda579aae9279696647dc397 | |
parent | ac7ae65b1ef20fcfa00ffab1ccd08d6327a1854f (diff) | |
download | bin-3b524772214090829493837e00423635ce29c59c.tar.gz bin-3b524772214090829493837e00423635ce29c59c.tar.xz |
sup: add options
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rwxr-xr-x | sup | 57 |
1 files changed, 54 insertions, 3 deletions
@@ -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() { @@ -21,6 +20,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] [--] <command ...>" + echo '' + echo 'Options:' + echo ' --help, -h this help' + echo ' --delay <number> amount of delay after enoguh failed runs' + echo ' --delay-after <number> amount of runs after which we wait' + echo ' --reset-after <number> 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 echo "sleeping for $delay seconds after $(($times_ran-1)) runs in $delay_reset_after seconds" >&2 @@ -30,7 +81,7 @@ while :; do time_started=`date +%s` echo -n "running... " >&2 - $command & + ${command[@]} & pid=$! echo PID: $pid >&2 wait $pid |