Created
January 30, 2022 01:50
-
-
Save gbluma/1dea9144019980344620ca88a730ad96 to your computer and use it in GitHub Desktop.
A short script to queue up a start job in proxmox, so that once the FROM vm is fully off, the TO vm is started. It's useful for swapping between GPU passthrough virtual machines without having to use another computer to start the next vm.
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 | |
FROM=$1 | |
TO=$2 | |
if [ -z "$FROM" ]; then echo "Usage: ./switch_vm.sh <current_vmid> <next_vmid>"; exit 1; fi | |
if [ -z "$TO" ]; then echo "Usage: ./switch_vm.sh <current_vmid> <next_vmid>"; exit 1; fi | |
echo "waiting for $FROM to shutdown, then starting $TO" | |
while : ; do | |
# read status for starting VM from qemu | |
status=$(qm status $FROM) | |
echo "$FROM = $status" | |
# if the vm reaches a stopped state | |
if [[ "$status" == *"stopped"* ]]; then | |
# ... start the next VM | |
echo "starting $TO..." | |
qm start $TO | |
echo "started." | |
# and exit | |
exit 0 | |
fi | |
sleep 1 | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment