910-poweroff-allvms
#!/bin/bash
#
# Power off all running VMs
#
# Run user check
if [ "$UID" -eq 0 ]
  then echo "This script should NOT be run as root."
  exit 1
fi
#
# Source config file
if [ ! -f ~/.vbconfig ]; then
    echo "Config File ~/.vbconfig not found!"
    echo "Run: set-folders to create .vbconfig"
    exit 1
fi
. ~/.vbconfig
#
# Sleep interval between powerdowns
#SLEEPINT=11
SLEEPINT=3
#
RUN_VM_LIST=`VBoxManage list runningvms|awk '{print $1}'`
for VM in $RUN_VM_LIST
do
  VM1="${VM//\"}"
  #echo "ACPI Powerdown of VM $VM1"
  #VBoxManage controlvm "${VM1}" acpipowerbutton
  echo "Save-state VM $VM1"
  VBoxManage controlvm "${VM1}" savestate
  echo "Sleeping $SLEEPINT seconds ..."
  sleep $SLEEPINT
done
#
exit