#!/usr/bin/env bash 

# requirements: * Linux server with KVM virtualization system
#               * libvirt-tools including virsh (Debian/Ubuntu: apt install libvirt-clients)
#               * virtual machines named 'vm-<nnn>'

# usage:   stop-vms.sh <start> <end>
# example: stop-vms.sh 10 29
#          shuts down 20 existing virtual machines named vm-10 to vm-29
if [ $# -ne 2 ]; then
    echo "usage: stop-vms.sh <start> <end>"
    exit 1
fi
vmstart=$1
vmend=$2

for (( nr=$vmstart; nr<=$vmend; nr++ )); do
  echo "stop vm-$nr"
  virsh shutdown "vm-$nr"
done
