├── lxc-exec-all ├── lxc-exec ├── README.md ├── lxc-update-all └── LICENSE /lxc-exec-all: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CONTAINERS=( $(pct list | grep running | awk '{print $1}') ) 4 | 5 | for CONTAINER in ${CONTAINERS[@]} 6 | do 7 | lxc-exec $CONTAINER "$@" 8 | done 9 | -------------------------------------------------------------------------------- /lxc-exec: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $1 =~ ^[0-9]*$ ]]; then 4 | if [ -d /sys/fs/cgroup/cpu/lxc/$1 ]; then 5 | CONTAINER=$1 6 | shift 7 | COMMAND=$@ 8 | echo -ne "\e[1;32mexecuting \"$COMMAND\" in container #${CONTAINER} ($(grep -m 1 hostname /etc/pve/lxc/${CONTAINER}.conf | awk '{print $NF}'))\e[0m\n" 9 | pct exec $CONTAINER /bin/sh -- -c "$COMMAND" 10 | else 11 | echo -ne "\e[1;31mcontainer $1 is not running\e[0m\n" 12 | exit 1 13 | fi 14 | fi 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pve-lxc-scripts 2 | 3 | Some useful scripts fpr Proxmox VE (PVE) LXC containers 4 | 5 | ## lxc-exec 6 | 7 | Execute a command inside a running container. 8 | 9 | **Example** 10 | 11 | ```bash 12 | lxc-exec 1337 apt-get update 13 | lxc-exec 1337 apt-get install vim -y 14 | ``` 15 | 16 | ## lxc-exec-all 17 | 18 | Execute a command inside all running containers using ```lxc-exec```. 19 | 20 | **Example** 21 | 22 | ```bash 23 | lxc-exec-all apt-get update 24 | lxc-exec-all apt-get install vim -y 25 | ``` 26 | 27 | ## lxc-update-all 28 | 29 | Update software on all running containers using ```lxc-exec```. 30 | 31 | ### Supported systems 32 | 33 | * apt-get 34 | * yum 35 | -------------------------------------------------------------------------------- /lxc-update-all: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CONTAINERS=( $(pct list | grep running | awk '{print $1}') ) 4 | 5 | apt_update() { 6 | pct exec $CONTAINER "apt-get update" 7 | pct exec $CONTAINER "apt-get dist-upgrade -y" 8 | pct exec $CONTAINER "apt-get clean" 9 | pct exec $CONTAINER "apt-get autoremove -y" 10 | } 11 | 12 | yum_update() { 13 | pct exec $CONTAINER "yum -y update" 14 | } 15 | 16 | apk_update() { 17 | pct exec $CONTAINER "apk upgrade" 18 | } 19 | 20 | for CONTAINER in ${CONTAINERS[@]} 21 | do 22 | pct exec $CONTAINER "which apt-get >/dev/null" && apt_update 23 | pct exec $CONTAINER "which yum >/dev/null" && yum_update 24 | pct exec $CONTAINER "which apk >/dev/null" && apk_update 25 | done 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 morph027 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | --------------------------------------------------------------------------------