User Tools

Site Tools


lab:proxmox:update-all-containers

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

lab:proxmox:update-all-containers [2021-06-01 20:29] (current)
wiki@tomr.me created
Line 1: Line 1:
 +====== Update all LXC Containers ======
  
 +<code bash update-all-containers.sh>
 +#!/bin/bash
 +# update all containers
 +
 +# list of container ids we need to iterate through
 +containers=$(pct list | tail -n +2 | cut -f1 -d' ')
 +
 +function update_container() {
 +  container=$1
 +  echo "[Info] Updating $container"
 +  # to chain commands within one exec we will need to wrap them in bash
 +  pct exec $container -- bash -c "apt update && apt upgrade -y && apt autoremove -y"
 +}
 +
 +for container in $containers
 +do
 +  status=`pct status $container`
 +  if [ "$status" == "status: stopped" ]; then
 +    echo [Info] Starting $container
 +    pct start $container
 +    echo [Info] Sleeping 5 seconds
 +    sleep 5
 +    update_container $container
 +    echo [Info] Shutting down $container
 +    pct shutdown $container &
 +  elif [ "$status" == "status: running" ]; then
 +    update_container $container
 +  fi
 +done; wait
 +</code>
 +
 +Source: https://forum.proxmox.com/threads/update-all-lxc-with-one-simple-script.58729/
/var/www/dokuwiki/data/pages/lab/proxmox/update-all-containers.txt · Last modified: 2021-06-01 20:29 by wiki@tomr.me