From c3e9de982dbf96b2920e6641702acd788192baea Mon Sep 17 00:00:00 2001 From: Alessandro Battilani Date: Fri, 9 Feb 2024 17:57:43 +0100 Subject: [PATCH] check status --- update-lxc-container.sh | 8 ++++---- update-lxc-single-container.sh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/update-lxc-container.sh b/update-lxc-container.sh index fc140d1..f6d37cd 100755 --- a/update-lxc-container.sh +++ b/update-lxc-container.sh @@ -12,10 +12,10 @@ function stop_container() { } echo $(date) "- Start updating LXC container..." -for i in $(lxc list type=container -c ns --format csv); do - cont_name=${i%,*} +for cont_name in $(lxc list type=container -c n --format csv); do echo $(date) "- Updating ${cont_name} container..." - if [ "${i#*,}" == "STOPPED" ]; then + Status=$(lxc list type=container -c ns --format csv | grep ${cont_name} | cut -d',' -f 2) + if [ "${Status}" == "STOPPED" ]; then echo -e $(date) "- ${BGreen}Start container ${cont_name}${Color_Off}" lxc start ${cont_name} sleep 5 @@ -31,7 +31,7 @@ for i in $(lxc list type=container -c ns --format csv); do echo -e $(date) "- Refresh snap packages" lxc exec ${cont_name} -- bash -c "if [[ \$(which snap > /dev/null; echo \$?) == 0 ]]; then snap refresh ; fi" - if [ "${i#*,}" == "STOPPED" ]; then + if [ "${Status}" == "STOPPED" ]; then echo $(date) "- Stop container ${cont_name}" stop_container ${cont_name} & pids[${cont_name}]=$! diff --git a/update-lxc-single-container.sh b/update-lxc-single-container.sh index 2e6d0e1..e7703fd 100755 --- a/update-lxc-single-container.sh +++ b/update-lxc-single-container.sh @@ -15,7 +15,7 @@ if [[ $1 == '' ]]; then fi echo $(date) "- Start updating $1 LXC container..." -status=$(lxc info microk8s | grep Status | cut -d' ' -f 2) +status=$(lxc info $1 | grep Status | cut -d' ' -f 2) echo $(date) "- Updating $1 container..." if [ $status == "STOPPED" ]; then