How to start/stop all VMs except one


ZataH

Recommended Posts

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. 

Link to comment

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 by ZataH
  • Like 1
Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.