# Proxmox LXC update automation
Tags: Proxmox Homelab Linux Selfhosting
Reading time: 3 minutes
Description: A simple script to update all LXC's on Proxmox
The following is a little script i use to update my LXC’s on Proxmox, it takes the current state, lock and operating system of the container into account.
Container are only updated if they are:
- running
- not locked (no ongoing backup, restore, …)
- in the list of known operating systems
# Detecting the OS
Almost every linux distribution has a little file in their /etc
directory, containing basic system information.
The name of this file changed a few times but is currently os-release
This file contains information about the distribution, in the case of my Gentoo system:
|
|
We can ignore almost everything since we only need the NAME
field (you could also use the ID
instead) which can be extracted with:
|
|
# Executing commands from the host in a container
Since we want this information about the container, not the host, we need to execute it in the target lxc.
This can be done via the pct exec
command (lxcid would be the numeric id of the container):
|
|
# The actual update part
Knowing the distribution, we can use a case
statement in combination with pct exec
to execute the update command.
To provide some readabiliyt, the distribution name is definted as a constant at the beginning of the script.
Now we only need to iterate over the running, not locked LXC’s and update them.
|
|
# Extending the script with more distributions
Create another constant at the beginning of the file with the information obtained from /etc/os-release
and expand the case statement.