From 0ee1015dcb72978a41736c6b340a235fa593f595 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Sun, 1 Jan 2023 12:07:17 +0100 Subject: [PATCH] add verbose option --- timeout | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/timeout b/timeout index 022dcda..d501dd7 100755 --- a/timeout +++ b/timeout @@ -17,7 +17,11 @@ create_script() { } run_script() { - "$SCRIPT_FILE" >/dev/null 2>&1 & + if [ "$2" -eq 0 ]; then + "$SCRIPT_FILE" >/dev/null 2>&1 & + else + "$SCRIPT_FILE" >&2 & + fi printf "%d" $! } @@ -39,16 +43,18 @@ check_pid() { } main() { - while getopts "ht:c:" option; do + while getopts "ht:c:v" option; do case "${option}" in h) usage; exit 0;; t) TIMEOUT="$OPTARG";; c) COMMAND="$OPTARG";; + v) VERBOSE=1;; *) usage; exit 1;; esac done TIMEOUT="${TIMEOUT:-10}" + VERBOSE="${VERBOSE:-0}" if [ -z "$COMMAND" ]; then printf "Command is required!\n" @@ -59,7 +65,7 @@ main() { create_script "$COMMAND" "$SCRIPT_FILE" - SCRIPT_PID=$(run_script "$SCRIPT_FILE") + SCRIPT_PID=$(run_script "$SCRIPT_FILE" "$VERBOSE") EXIT_STATUS=$(check_pid "$SCRIPT_PID" "$TIMEOUT") stop_delete_script "$SCRIPT_PID" "$SCRIPT_FILE"