Skip to content

Instantly share code, notes, and snippets.

@Mic92
Created April 12, 2015 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mic92/f7abdd6cbd814d4399ad to your computer and use it in GitHub Desktop.
Save Mic92/f7abdd6cbd814d4399ad to your computer and use it in GitHub Desktop.
Execute a command for every lxc instance
#!/bin/bash
# replace this with your rootfs
lxc_root=/data/containers
for n in `lxc-ls`; do
name=n
r=$lxc_root/$n/rootfs
root=$r
c=$lxc_root/$n/config
config=$c
eval echo "\$ $1" 1>&2
eval "$1"
done
# example usage
$ lxc-foreach 'lxc-attach -n $n -- apt-get upgrade'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment