--- a/run-one 2013-03-04 18:02:15.513983439 -0500 +++ b/run-one 2013-03-05 15:27:46.635948096 -0500 @@ -32,14 +32,15 @@ mkdir -p "$DIR" # Calculate the hash of the command and arguments +CMD="$@" CMDHASH=$(echo "$@" | md5sum | awk '{print $1}') FLAG="$DIR/$CMDHASH" # Handle run-this-one invocation, by killing matching process first case "$(basename $0)" in run-one) - # Run the specified commands, assuming we can flock this command string's hash - flock -xn "$FLAG" "$@" + # Run the specified command, assuming we can flock this command string's hash + flock -xn "$FLAG" -c "$CMD" ;; run-this-one) ps="$@" @@ -58,15 +59,15 @@ pid=$(lsof "$FLAG" | awk '{print $2}' | grep "^[0-9]") || true [ -z "$pid" ] || kill $pid sleep 0.1 - # Run the specified commands, assuming we can flock this command string's hash - flock -xn "$FLAG" "$@" + # Run the specified command, assuming we can flock this command string's hash + flock -xn "$FLAG" -c "$CMD" ;; keep-one-running) backoff=1 while true; do - # Run the specified commands, assuming we can flock this command string's hash + # Run the specified command, assuming we can flock this command string's hash set +e - flock -xn "$FLAG" "$@" + flock -xn "$FLAG" -c "$CMD" if [ "$?" = 0 ]; then # Last run finished successfully, reset to minimum back-off of 1 second backoff=1