From 7af36bb1a402b1714dffe57d1eb71edb60f84e5a Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 21:31:01 -0600 Subject: [PATCH 01/33] testing cmd-to-container --- functions/cmd_to_container.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index dfbc5215..3752d6c0 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -27,10 +27,10 @@ mapfile -t pod_id < <(k3s crictl pods -s ready --namespace ix | grep -E "[[:spac search=$(k3s crictl ps -a -s running | sed -E 's/[[:space:]]([0-9]*|About)[a-z0-9 ]{5,12}ago[[:space:]]//') for pod in "${pod_id[@]}" do - if [[ $(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r " | wc -l) -gt 1 ]]; then - readarray -t containers <<<"$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" - continue - fi + # if [[ $(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r " | wc -l) -gt 1 ]]; then + # readarray -t containers <<<"$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" + # continue + # fi printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue containers+=("$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")") From 9696082cc8c2d935303b417f9da4244afbbd8c2d Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 21:36:27 -0600 Subject: [PATCH 02/33] test array rebuild --- functions/cmd_to_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index 3752d6c0..66c606ce 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -33,8 +33,8 @@ do # fi printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue containers+=("$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")") - done +readarray -t containers <<<"${containers[@]}" case "${#containers[@]}" in 0) echo -e "No containers available\nAre you sure the application in running?" From d518de6e67b1aef1daf16165d5e1c9b536c0efa0 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 21:37:56 -0600 Subject: [PATCH 03/33] change from var to array --- functions/cmd_to_container.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index 66c606ce..0491dd3a 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -32,9 +32,9 @@ do # continue # fi printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue - containers+=("$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")") + containers+="$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" done -readarray -t containers <<<"${containers[@]}" +readarray -t containers <<<"$containers" case "${#containers[@]}" in 0) echo -e "No containers available\nAre you sure the application in running?" From a0037cb4d095312f9387ae37aa9ac82e0025c89a Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 21:43:01 -0600 Subject: [PATCH 04/33] read IFS --- functions/cmd_to_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index 0491dd3a..b9bae6cc 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -34,7 +34,7 @@ do printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue containers+="$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" done -readarray -t containers <<<"$containers" +IFS=" " read -r -a containers <<< "$containers" case "${#containers[@]}" in 0) echo -e "No containers available\nAre you sure the application in running?" From 389e0fbcd05fd86673c809122ef007e70270cffc Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 21:50:59 -0600 Subject: [PATCH 05/33] readarray --- functions/cmd_to_container.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index b9bae6cc..1429b9fc 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -34,7 +34,8 @@ do printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue containers+="$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" done -IFS=" " read -r -a containers <<< "$containers" +readarray -t containers <<<"$containers" + case "${#containers[@]}" in 0) echo -e "No containers available\nAre you sure the application in running?" From ba17b0dd136310601d4e31c1d2966410e6c2fcca Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 21:51:57 -0600 Subject: [PATCH 06/33] trying to rebuild array --- functions/cmd_to_container.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index 1429b9fc..4db51b53 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -32,9 +32,9 @@ do # continue # fi printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue - containers+="$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" + containers+=("$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")") done -readarray -t containers <<<"$containers" +readarray -t containers <<<"${containers[*]}" case "${#containers[@]}" in 0) From bc9fed707e67653ee55a84de7390d2784a4a53d5 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 21:58:24 -0600 Subject: [PATCH 07/33] rebuild array --- functions/cmd_to_container.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index 4db51b53..c05228ba 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -34,8 +34,7 @@ do printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue containers+=("$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")") done -readarray -t containers <<<"${containers[*]}" - +readarray -td, containers <<<"${containers[@]}"; declare -p containers; case "${#containers[@]}" in 0) echo -e "No containers available\nAre you sure the application in running?" From 0b786c3ef263412e60328a2019e60da66c16853f Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:01:08 -0600 Subject: [PATCH 08/33] make only var --- functions/cmd_to_container.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index c05228ba..1ed5bd2d 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -32,9 +32,9 @@ do # continue # fi printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue - containers+=("$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")") + containers+="$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" done -readarray -td, containers <<<"${containers[@]}"; declare -p containers; +readarray -td, containers <<<"$containers"; declare -p containers; case "${#containers[@]}" in 0) echo -e "No containers available\nAre you sure the application in running?" From 354e132d8fd7d50558709cb0288f7763fe5ade9f Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:04:42 -0600 Subject: [PATCH 09/33] array rebuild --- functions/cmd_to_container.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index 1ed5bd2d..cfdc13a8 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -32,9 +32,9 @@ do # continue # fi printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue - containers+="$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" + containers+=("$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")") done -readarray -td, containers <<<"$containers"; declare -p containers; +containers=("${containers[@]}") case "${#containers[@]}" in 0) echo -e "No containers available\nAre you sure the application in running?" From 0aee51e7120e4ee25dc6be78cf66f2742955535d Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:07:59 -0600 Subject: [PATCH 10/33] test --- functions/cmd_to_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index cfdc13a8..0ef71f46 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -34,7 +34,7 @@ do printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue containers+=("$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")") done -containers=("${containers[@]}") +containers=$("$("${containers[@]}")") case "${#containers[@]}" in 0) echo -e "No containers available\nAre you sure the application in running?" From 4ed623d0ab29bfdce4c2c30710958d6b3816f214 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:10:49 -0600 Subject: [PATCH 11/33] mapfile --- functions/cmd_to_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index 0ef71f46..ed18e75e 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -34,7 +34,7 @@ do printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue containers+=("$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")") done -containers=$("$("${containers[@]}")") +mapfile -t containers < <("${containers[@]}") case "${#containers[@]}" in 0) echo -e "No containers available\nAre you sure the application in running?" From 8b60029b375d63879e3b29be2970c9b862f11d2a Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:11:35 -0600 Subject: [PATCH 12/33] echo containers --- functions/cmd_to_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index ed18e75e..af0eaf7f 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -34,7 +34,7 @@ do printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue containers+=("$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")") done -mapfile -t containers < <("${containers[@]}") +mapfile -t containers < <("echo ${containers[*]}") case "${#containers[@]}" in 0) echo -e "No containers available\nAre you sure the application in running?" From 3cacd0bb80e277be3b79d953e90a3036daebff83 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:12:13 -0600 Subject: [PATCH 13/33] quotations --- functions/cmd_to_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index af0eaf7f..84cb7291 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -34,7 +34,7 @@ do printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue containers+=("$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")") done -mapfile -t containers < <("echo ${containers[*]}") +mapfile -t containers < <(echo "${containers[*]}") case "${#containers[@]}" in 0) echo -e "No containers available\nAre you sure the application in running?" From 61bf2efe8509b46d3c3fcbaed05a2fcb2e726c8e Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:13:09 -0600 Subject: [PATCH 14/33] echo array for testting --- functions/cmd_to_container.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index 84cb7291..bde8c2e9 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -35,6 +35,10 @@ do containers+=("$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")") done mapfile -t containers < <(echo "${containers[*]}") +for i in "${containers[@]}" +do + echo "$i" +done case "${#containers[@]}" in 0) echo -e "No containers available\nAre you sure the application in running?" From 509ee9054326e55af272d93d537d059271c6639f Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:14:48 -0600 Subject: [PATCH 15/33] print array elements --- functions/cmd_to_container.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index bde8c2e9..2541e095 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -39,6 +39,7 @@ for i in "${containers[@]}" do echo "$i" done +printf '%s\n' "${containers[@]}" case "${#containers[@]}" in 0) echo -e "No containers available\nAre you sure the application in running?" From ec37299970a7c763ea1c265a2b3cec719a2591ce Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:16:28 -0600 Subject: [PATCH 16/33] space in print output --- functions/cmd_to_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index 2541e095..f3b97e6c 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -39,7 +39,7 @@ for i in "${containers[@]}" do echo "$i" done -printf '%s\n' "${containers[@]}" +printf '%s \n' "${containers[@]}" case "${#containers[@]}" in 0) echo -e "No containers available\nAre you sure the application in running?" From cc43fb198374f682359fc23a683067aade233b52 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:21:17 -0600 Subject: [PATCH 17/33] change to newline with sed --- functions/cmd_to_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index f3b97e6c..d4a1d79e 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -32,7 +32,7 @@ do # continue # fi printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue - containers+=("$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")") + containers+=("$(echo "$search" | grep "$pod" | awk '{print $4}' | sed 's/ /\n//')") done mapfile -t containers < <(echo "${containers[*]}") for i in "${containers[@]}" From ed96807938053d0ccb1b0a8aa45276f3e48448af Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:26:06 -0600 Subject: [PATCH 18/33] try using a file --- functions/cmd_to_container.sh | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index d4a1d79e..19e4a7a3 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -31,15 +31,12 @@ do # readarray -t containers <<<"$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" # continue # fi - printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue - containers+=("$(echo "$search" | grep "$pod" | awk '{print $4}' | sed 's/ /\n//')") + # printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue + "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" >> containers done -mapfile -t containers < <(echo "${containers[*]}") -for i in "${containers[@]}" -do - echo "$i" -done -printf '%s \n' "${containers[@]}" + +cat containers + case "${#containers[@]}" in 0) echo -e "No containers available\nAre you sure the application in running?" From 7907af24ba2ee2178fbc2b59d318d273a74043dd Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:26:51 -0600 Subject: [PATCH 19/33] dont supress output --- functions/cmd_to_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index 19e4a7a3..f0745b97 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -32,7 +32,7 @@ do # continue # fi # printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue - "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" >> containers + echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r " >> containers done cat containers From 7615f645543c61c1d0ccec626ca08891493d981d Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:28:37 -0600 Subject: [PATCH 20/33] try file --- functions/cmd_to_container.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index f0745b97..df336f63 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -32,10 +32,10 @@ do # continue # fi # printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue - echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r " >> containers + echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r " >> cont_file done -cat containers +mapfile -t containers < cont_file case "${#containers[@]}" in 0) From 765a56a04883f930654593824b5d10cb9b0c48e8 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:31:21 -0600 Subject: [PATCH 21/33] rm file and sort --- functions/cmd_to_container.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index df336f63..dbb7d76b 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -22,6 +22,7 @@ do break fi done +rm cont_file 2> /dev/null app_name=$(echo -e "$app_name" | grep ^"$selection)" | awk '{print $2}') mapfile -t pod_id < <(k3s crictl pods -s ready --namespace ix | grep -E "[[:space:]]$app_name([[:space:]]|-([-[:alnum:]])*[[:space:]])" | awk '{print $1}') search=$(k3s crictl ps -a -s running | sed -E 's/[[:space:]]([0-9]*|About)[a-z0-9 ]{5,12}ago[[:space:]]//') @@ -34,9 +35,8 @@ do # printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r " >> cont_file done - -mapfile -t containers < cont_file - +mapfile -t containers < "$(sort -u cont_file)" +rm cont_file 2> /dev/null case "${#containers[@]}" in 0) echo -e "No containers available\nAre you sure the application in running?" From ffd0d1aaeb90f5a2e9baf61d5a8565fcf0a06a4e Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:32:38 -0600 Subject: [PATCH 22/33] sort and clean --- functions/cmd_to_container.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index dbb7d76b..b8724a66 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -35,7 +35,8 @@ do # printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r " >> cont_file done -mapfile -t containers < "$(sort -u cont_file)" +clean_list=$(sort -u cont_file) +mapfile -t containers < "$clean_list" rm cont_file 2> /dev/null case "${#containers[@]}" in 0) From fe7604130318c5ca6e57c47d8bd85fa5cc83de10 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:33:46 -0600 Subject: [PATCH 23/33] proper redirection --- functions/cmd_to_container.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index b8724a66..2adeba8f 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -35,8 +35,7 @@ do # printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r " >> cont_file done -clean_list=$(sort -u cont_file) -mapfile -t containers < "$clean_list" +mapfile -t containers < <(sort -u cont_file) rm cont_file 2> /dev/null case "${#containers[@]}" in 0) From d930c734f733f46cd9f5b59e78fb6dae2bdcde98 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:36:24 -0600 Subject: [PATCH 24/33] remove error message on STOPPED application --- functions/cmd_to_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index 2adeba8f..09f2ee55 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -35,7 +35,7 @@ do # printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r " >> cont_file done -mapfile -t containers < <(sort -u cont_file) +mapfile -t containers < <(sort -u cont_file 2> /dev/null) rm cont_file 2> /dev/null case "${#containers[@]}" in 0) From 25cbd91818b52789e063a245be7deb9c03accb9d Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:44:55 -0600 Subject: [PATCH 25/33] also grep pod for addon containers --- functions/cmd_to_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index 09f2ee55..cda66710 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -74,7 +74,7 @@ case "${#containers[@]}" in fi done container=$(echo "$cont_search" | grep ^"$selection)" | awk '{print $2}') - container_id=$(echo "$search" | grep -E "[[:space:]]${container}[[:space:]]" | awk '{print $1}') + container_id=$(echo "$search" | grep -E "[[:space:]]${container}[[:space:]]" | grep "${pod_id[0]}" | awk '{print $1}') ;; esac while true From fe8abe8938868c50b50198abb62c07d9add7f84d Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:48:03 -0600 Subject: [PATCH 26/33] revert. looking for better solution --- functions/cmd_to_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index cda66710..09f2ee55 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -74,7 +74,7 @@ case "${#containers[@]}" in fi done container=$(echo "$cont_search" | grep ^"$selection)" | awk '{print $2}') - container_id=$(echo "$search" | grep -E "[[:space:]]${container}[[:space:]]" | grep "${pod_id[0]}" | awk '{print $1}') + container_id=$(echo "$search" | grep -E "[[:space:]]${container}[[:space:]]" | awk '{print $1}') ;; esac while true From 58a72fafb3d0d7e1c1e196b90c7a2605e22a6c3c Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:58:29 -0600 Subject: [PATCH 27/33] testing output for new file --- functions/cmd_to_container.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index 09f2ee55..e68fb3b2 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -28,15 +28,10 @@ mapfile -t pod_id < <(k3s crictl pods -s ready --namespace ix | grep -E "[[:spac search=$(k3s crictl ps -a -s running | sed -E 's/[[:space:]]([0-9]*|About)[a-z0-9 ]{5,12}ago[[:space:]]//') for pod in "${pod_id[@]}" do - # if [[ $(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r " | wc -l) -gt 1 ]]; then - # readarray -t containers <<<"$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" - # continue - # fi - # printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue - echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r " >> cont_file + echo "$search" | grep "$pod" | tr -d " \t\r " >> cont_file done mapfile -t containers < <(sort -u cont_file 2> /dev/null) -rm cont_file 2> /dev/null +# rm cont_file 2> /dev/null case "${#containers[@]}" in 0) echo -e "No containers available\nAre you sure the application in running?" @@ -46,7 +41,6 @@ case "${#containers[@]}" in container=$(echo "$search" | grep "${pod_id[0]}" | awk '{print $4}') container_id=$(echo "$search" | grep -E "[[:space:]]${container}[[:space:]]" | awk '{print $1}') ;; - *) while true do From 6e6bfe7bf844b632b7939338cabfc38acb1ecec5 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 22:59:29 -0600 Subject: [PATCH 28/33] rm tr --- functions/cmd_to_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index e68fb3b2..4c6bc98e 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -28,7 +28,7 @@ mapfile -t pod_id < <(k3s crictl pods -s ready --namespace ix | grep -E "[[:spac search=$(k3s crictl ps -a -s running | sed -E 's/[[:space:]]([0-9]*|About)[a-z0-9 ]{5,12}ago[[:space:]]//') for pod in "${pod_id[@]}" do - echo "$search" | grep "$pod" | tr -d " \t\r " >> cont_file + echo "$search" | grep "$pod" >> cont_file done mapfile -t containers < <(sort -u cont_file 2> /dev/null) # rm cont_file 2> /dev/null From 9af91e1e51d36c6d6e5d6b7f7276454a4eb601fc Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 23:02:12 -0600 Subject: [PATCH 29/33] grep from file --- functions/cmd_to_container.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index 4c6bc98e..f2d3bc73 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -38,8 +38,8 @@ case "${#containers[@]}" in exit ;; 1) - container=$(echo "$search" | grep "${pod_id[0]}" | awk '{print $4}') - container_id=$(echo "$search" | grep -E "[[:space:]]${container}[[:space:]]" | awk '{print $1}') + container=$(grep "${pod_id[0]}" cont_file | awk '{print $4}') + container_id=$(grep -E "[[:space:]]${container}[[:space:]]" cont_file | awk '{print $1}') ;; *) while true From 2dfd8b01ab3c89f481bd8e9ea98b6a74712b7618 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 23:04:03 -0600 Subject: [PATCH 30/33] print name --- functions/cmd_to_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index f2d3bc73..88e395a9 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -49,7 +49,7 @@ case "${#containers[@]}" in cont_search=$( for i in "${containers[@]}" do - echo "$i" + echo "$i | awk '{print $4}'" done | nl -s ") " | column -t ) echo "$cont_search" From b5c3bdaf0db3b7fe2d88726fd5a2c91b71419f82 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 23:04:40 -0600 Subject: [PATCH 31/33] undo literal awk lol --- functions/cmd_to_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index 88e395a9..3a6af823 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -49,7 +49,7 @@ case "${#containers[@]}" in cont_search=$( for i in "${containers[@]}" do - echo "$i | awk '{print $4}'" + echo "$i" | awk '{print $4}' done | nl -s ") " | column -t ) echo "$cont_search" From 518f7fa0d1806a99554bcaf585085c36b83c1c29 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 23:05:46 -0600 Subject: [PATCH 32/33] rm file once func is done --- functions/cmd_to_container.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index 3a6af823..e40a1175 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -31,7 +31,6 @@ do echo "$search" | grep "$pod" >> cont_file done mapfile -t containers < <(sort -u cont_file 2> /dev/null) -# rm cont_file 2> /dev/null case "${#containers[@]}" in 0) echo -e "No containers available\nAre you sure the application in running?" @@ -109,6 +108,6 @@ do ;; esac done - +rm cont_file 2> /dev/null } export -f cmd_to_container \ No newline at end of file From 58e7765794772eea5e9ff668c36b35d33a5df80c Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Sun, 21 Aug 2022 23:12:32 -0600 Subject: [PATCH 33/33] fix container_id var --- functions/cmd_to_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index e40a1175..72f79990 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -67,7 +67,7 @@ case "${#containers[@]}" in fi done container=$(echo "$cont_search" | grep ^"$selection)" | awk '{print $2}') - container_id=$(echo "$search" | grep -E "[[:space:]]${container}[[:space:]]" | awk '{print $1}') + container_id=$(grep -E "[[:space:]]${container}[[:space:]]" cont_file | awk '{print $1}') ;; esac while true