From 558100ae20eed8651925f225db3cf6f82803d437 Mon Sep 17 00:00:00 2001 From: Mathias Koehler Date: Sat, 29 Apr 2023 20:37:39 +0200 Subject: [PATCH] Add trap to wait for jobs to handle sigint --- stream.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/stream.sh b/stream.sh index 1a928f1..ee16ce2 100755 --- a/stream.sh +++ b/stream.sh @@ -12,9 +12,20 @@ fi declare -A STREAMS +sigint() { + for pid in "${STREAMS[@]}"; do + wait "$pid" + done +} + +trap sigint INT + failed() { - echo "Streaming $1 failed" - tail -n 5 "/tmp/$1_log" + file=$1 + echo "Streaming $file failed" + tail -n 5 "/tmp/${file}_log" + + unset "STREAMS[$file]" } streaming() { @@ -31,6 +42,8 @@ streaming() { > "/tmp/$1_log" \ 2>&1 ) || failed "$1" + + unset "STREAMS[$file]" } check() {