From a8b60f5c7175cd95c0aa6426991367067873cb7d Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Wed, 10 Aug 2022 16:58:07 -0600 Subject: [PATCH] check for number of containers not pods --- functions/cmd_to_container.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index 56274270..8c68f768 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -25,24 +25,30 @@ done app_name=$(echo -e "$app_name" | grep ^"$selection)" | awk '{print $2}') search=$(k3s crictl ps -a -s running | sed -E 's/([0-9]*|About)[[:space:]][a-z]{2,5}[[:space:]](hour)?[[:space:]]?ago//') mapfile -t pod_id < <(echo "$search" | grep -E "[[:space:]]$app_name([[:space:]]|-([-[:alnum:]])*[[:space:]])" | awk '{print $(NF)}') +for pod in "${pod_id[@]}" +do + mapfile -t containers < <(echo "$search" | grep "$pod" | awk '{print $4}') +done -if [[ "${#pod_id[@]}" == 1 ]]; then +if [[ "${#containers[@]}" == 1 ]]; then container=$(echo "$search" | grep "${pod_id[*]}" | awk '{print $4}') container_id=$(echo "$search" | grep -E "[[:space:]]${container}[[:space:]]" | awk '{print $1}') -elif [[ "${#pod_id[@]}" == 0 ]]; then +elif [[ "${#containers[@]}" == 0 ]]; then echo -e "No containers available\nAre you sure the application in running?" exit else - containers=$( for pod in "${pod_id[@]}" do - echo "$search" | grep "$pod" | awk '{print $4}' - done | nl -s ") " | column -t) + mapfile -t containers < <(echo "$search" | grep "$pod" | awk '{print $4}') + done while true do clear -x title - echo "$containers" + for container in "${containers[@]}" + do + echo "$container" + done | nl -s ") " | column -t echo echo "0) Exit" read -rt 120 -p "Choose a container by number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; }