Last active
January 6, 2022 00:24
-
-
Save dadatuputi/49a9024d24d010f5a2cb514c37e68fed to your computer and use it in GitHub Desktop.
Update all Proxmox containers
This file contains 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 | |
# update all containers | |
# modified from https://seantemple.com/proxmox/bash/admin/2017/10/01/update-all-containers.html | |
function update_container() { | |
container=$1 | |
tmux new-window -t $2:$3 -n "$container" -d | |
tmux send-keys -t $2:$3 "pct exec $container -- bash -c 'apt update && apt upgrade -y && apt autoremove -y && apt clean' ; tmux wait-for -S $container" Enter | |
tmux wait-for $container | |
tmux kill-window -t $2:$3 | |
} | |
function execute() { | |
# list of container ids we need to iterate through | |
containers=$(pct list | grep running | cut -f1 -d' ') | |
script=$1 | |
#tmux send-keys -t $script:0 "stty -echo ; clear" Enter | |
count=1 | |
for container in $containers | |
do | |
echo "$container updating..." | |
update_container $container $script $count & | |
((count+=1)) | |
done | |
wait | |
} | |
script=`basename "$0"` | |
if [[ $TERM == screen* ]] && [ -n "$TMUX" ]; then | |
# If we are in tmux, continue as normal | |
execute $script | |
tmux kill-session -t $script | |
else | |
# If we are not, run the script in tmux | |
# Initialize tmux session | |
tmux -2 new-session -s $script $0 | |
fi | |
echo "Updated all running containers" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment