Files
bash_mng_scripts/update-lxc-contaier.sh
2023-12-20 16:32:38 +01:00

21 lines
533 B
Bash
Executable File

#!/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