-
-
Save doug65536/ce7ba68758bbef582ab7ea2ebdd5715d to your computer and use it in GitHub Desktop.
LXD run command in all running containers, optionally in parallel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Run command in all running containers | |
# Usage: $ ./lxc-exec-all.sh apt update && apt upgrade | |
# | |
# To run in all in parallel, put '*' as the first argument. | |
# | |
if "$1"=="*" then | |
shift | |
# Run in parallel | |
sudo lxc list volatile.last_state.power=RUNNING -c n --format csv | \ | |
parallel -j $(nproc) -- sudo lxc exec '{}' -- "$@" || exit | |
else | |
# Sequential | |
for container in $(sudo lxc list volatile.last_state.power=RUNNING -c n --format csv); do | |
sudo lxc exec "$container" -- "$@" | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment