while loops to cmd to cnter

This commit is contained in:
Heavybullets8 2022-08-08 20:28:36 -06:00
parent 6bafce8181
commit 887e69cb36

View File

@ -215,14 +215,26 @@ case $selection in
;; ;;
9) 9)
title
clear -x
app_name=$(k3s kubectl get pods -A | awk '{print $1}' | sort -u | grep -v "system" | sed '1d' | sed 's/^[^-]*-//' | nl -s ") " | column -t) app_name=$(k3s kubectl get pods -A | awk '{print $1}' | sort -u | grep -v "system" | sed '1d' | sed 's/^[^-]*-//' | nl -s ") " | column -t)
while true
do
clear -x
title
echo "$app_name" echo "$app_name"
echo echo
echo "0) Exit" echo "0) Exit"
[[ $selection == 0 ]] && echo "Exiting.." && exit
read -rt 120 -p "Please type a number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; } read -rt 120 -p "Please type a number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; }
if [[ $selection == 0 ]]; then
echo "Exitting.."
exit
elif ! echo -e "$app_name" | grep -qs ^"$selection)" ; then
echo "Error: \"$selection\" was not an option.. Try again"
sleep 3
continue
else
break
fi
done
app_name=$(echo -e "$app_name" | grep ^"$selection)" | awk '{print $2}') app_name=$(echo -e "$app_name" | grep ^"$selection)" | awk '{print $2}')
search=$(k3s crictl ps -a -s running) search=$(k3s crictl ps -a -s running)
mapfile -t pod_id < <(echo "$search" | grep "$app_name" | awk '{print $9}') mapfile -t pod_id < <(echo "$search" | grep "$app_name" | awk '{print $9}')
@ -232,18 +244,35 @@ case $selection in
do do
echo "$search" | grep "$pod" | awk '{print $7}' echo "$search" | grep "$pod" | awk '{print $7}'
done | nl -s ") " | column -t) done | nl -s ") " | column -t)
while true
do
clear -x clear -x
title title
echo "$containers" echo "$containers"
echo echo
echo "0) Exit" echo "0) Exit"
read -rt 120 -p "Choose a container by number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; } read -rt 120 -p "Choose a container by number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; }
[[ $selection == 0 ]] && echo "Exiting.." && exit if [[ $selection == 0 ]]; then
echo "Exitting.."
exit
elif ! echo -e "$containers" | grep -qs ^"$selection)" ; then
echo "Error: \"$selection\" was not an option.. Try again"
sleep 3
continue
else
break
fi
done
container=$(echo "$containers" | grep ^"$selection)" | awk '{print $2}') container=$(echo "$containers" | grep ^"$selection)" | awk '{print $2}')
container_id=$(echo "$search" | grep "$container" | awk '{print $1}') container_id=$(echo "$search" | grep "$container" | awk '{print $1}')
clear -x
read -rt 120 -p "What command would you like to submit to $app_name on $container?: " command || { echo -e "\nFailed to make a selection in time" ; exit; } title
echo "App Name: $app_name"
echo "Container $container"
echo
echo "0) Exit"
read -rt 120 -p "What command would you like to run?: " command || { echo -e "\nFailed to make a selection in time" ; exit; }
[[ $command == 0 ]] && echo "Exitting.." && exit
k3s crictl exec "$container_id" $command k3s crictl exec "$container_id" $command
container=$(echo -e "$app_name" | grep ^"$selection)" | awk '{print $2}') container=$(echo -e "$app_name" | grep ^"$selection)" | awk '{print $2}')
;; ;;