#!/bin/bash for i in $(lxc list type=container -c ns --format csv); do echo $(date) "- Updating ${i%,*} container..." if [ "${i#*,}" == "STOPPED" ]; then echo $(date) "- Start container" lxc start ${i%,*} sleep 5 else echo $(date) "- Container is already started" fi lxc exec ${i%,*} -- sh -c "apt update" sleep 5 lxc exec ${i%,*} -- sh -c "apt upgrade -y" sleep 5 if [ "${i#*,}" == "STOPPED" ]; then echo $(date) "- Stop container" lxc stop ${i%,*} fi done