From 10cb46633b2839772a679aea3b303643024f7c89 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Mon, 25 Jul 2022 15:02:47 -0600 Subject: [PATCH] while loop --- functions/update_apps.sh | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/functions/update_apps.sh b/functions/update_apps.sh index f013b78c..29770ad2 100644 --- a/functions/update_apps.sh +++ b/functions/update_apps.sh @@ -9,32 +9,22 @@ mapfile -t array < <(cli -m csv -c 'app chart_release query name,update_availabl update_limit=2 current_updates=0 - -while true +it=0 +while [[ $it -lt ${#array[@]} ]] do - if [[ current_updates -ge "$update_limit" ]]; then - sleep 5 + jobs=$(jobs -p | wc -l) + if [[ "$jobs" -ge "$update_limit" ]]; then + sleep 3 else - for i in "${array[@]}" - do - { update_apps "$i"; (( current_updates-- )) ;} & (( current_updates++ )) - processes+=($!) - done + update_apps "${#array[$it]}" & + processes+=($!) + ((it++)) fi done - - - - - - - - - for proc in "${processes[@]}" do wait "$proc"