Home Check if LXC container OS version matches the host system on Debian
Post
Cancel

Check if LXC container OS version matches the host system on Debian

As part of my daily cron jobs I thought it would be nice to get an overview of which Debian version the system is running and if all LXC containers have a matching version. The script below will check this for you:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/sh

SYSTEM_VERSION="$(cat /etc/debian_version)"
echo "System version: $SYSTEM_VERSION" 
echo
CONTAINERS="`lxc-ls`"
for i in $CONTAINERS; do 
   CONTAINER_VERSION="$(cat /var/lib/lxc/$i/rootfs/etc/debian_version)" 
   if [ "$CONTAINER_VERSION" != "$SYSTEM_VERSION" ]; then
      echo " ❗️ $i: $CONTAINER_VERSION (upgrade required)" 
   else
      echo " ✅ $i: $CONTAINER_VERSION" 
   fi

done

Sample output:

1
2
3
4
5
6
System version: 11.5

 ✅ daapd: 11.5
 ✅ minecraft: 11.5
 ❗️ sonos: 10.13 (upgrade required)
 ✅ timemachine: 11.5
This post is licensed under CC BY 4.0 by the author.