#get list of VMs vboxmanage list vms #get list of running VMs vboxmanage list runningvms #which machines are running with containing "OSadmin" vboxmanage list runningvms | sed -r 's/^"(.*)".*$/\1/' | grep -i 'osadmin' #how many machines are running with containing "OSadmin" vboxmanage list runningvms | sed -r 's/^"(.*)".*$/\1/' | grep -i 'osadmin' | wc -l #how many machines are working vboxmanage list runningvms | wc -l #get running time vboxmanage showvminfo "Ubuntu Server" | grep 'running (since' #get IP-addresses of particular VM vboxmanage guestproperty enumerate "Ubuntu Server" | grep IP #shut down vboxmanage controlvm "Ubuntu Server" acpipowerbutton #power off - not suggested unless there is no other option, might damage file systems vboxmanage controlvm "Ubuntu Server" poweroff #reset to force reboot - not suggested unless there is no other option, might damage file systems vboxmanage controlvm "Ubuntu Server" reset * * * #turn all machines off su - vbox #if needed in server #!/bin/bash for i in $(VBoxManage list runningvms | cut -f1 -d' '| tr -d '"') do echo "Stopping $i" vboxmanage controlvm $i acpipowerbutton done * * * #turn off all machines containing name "OSadmin" su - vbox #if needed in server #!/bin/bash for i in $(VBoxManage list runningvms | sed -r 's/^"(.*)".*$/\1/' | grep 'OSadmin') do echo "Stopping $i" vboxmanage controlvm $i acpipowerbutton done * * * #close all running machines except infrastructure (e.g. router, proxy, dns) #!/bin/bash # Logs are in /var/log/vm_shutdown.log su -c "vboxmanage list runningvms | cut -d'\"' -f2" vbox > /tmp/runningvms if [ $? -ne 0 ]; then echo "Error getting running vms from vbox" > /var/log/vm_shutdown.log exit 0 fi egrep -v 'router|proxy|dns' /tmp/runningvms > /tmp/runningvms2 if [ $? -ne 0 ]; then echo "Error excluding infrastructure machines" >> /var/log/vm_shutdown.log exit 0 fi while read p; do su -c "vboxmanage controlvm $p acpipowerbutton" vbox if [ $? -ne 0 ]; then echo "Error shutting down $p " >> /var/log/vm_shutdown.log fi done