ZataH Posted December 7, 2019 Share Posted December 7, 2019 I need help with a script. I need a script where I can shutdown/start all VMs except one. I know about start/stopping via virsh, but I cant find information how to do this on all except one particular. Quote Link to comment
bastl Posted December 8, 2019 Share Posted December 8, 2019 Not sure if there is a comand to shutdown all except of one but you can virsh shutdown one by one. simply add a line for each VM in your script. Quote Link to comment
ZataH Posted December 8, 2019 Author Share Posted December 8, 2019 Just now, bastl said: Not sure if there is a comand to shutdown all except of one but you can virsh shutdown one by one. simply add a line for each VM in your script. Yeah I know how to do this, with a manual VM-list, but I dont want to edit that one, each time I create or edit my VMs. Quote Link to comment
ZataH Posted December 8, 2019 Author Share Posted December 8, 2019 (edited) Figured it out In case anyone wants it VM-Shutdown: #!/bin/bash #Empty vm list echo "" > /tmp/vms-running.txt #Get all running vms except backup server for VM in $(virsh list --state-running --name); do if [[ ! "$VM" == "VM-TO-NOT-SHUTDOWN" ]] ; then virsh shutdown "$VM" #Write running vms to list echo "$VM" >> /tmp/vms-running.txt fi done /usr/local/emhttp/webGui/scripts/notify -i normal -s "Veeam started - VMs shutdown" VM-Start: #!/bin/bash #Get all running vms except backup server for VM in $(cat /tmp/vms-running.txt); do virsh start "$VM" done /usr/local/emhttp/webGui/scripts/notify -i normal -s "Veeam done - VMs started" Edited December 9, 2019 by ZataH 1 Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.