Last active
May 30, 2019 19:40
-
-
Save kennith/9375d90d918cc408bf4f721c161e06ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function vm-shutdown() { | |
echo 'Shutdown running VM(s)'; | |
# Get a list of VMs that are running and put them into array | |
vms=($(/usr/local/bin/VBoxManage list runningvms | awk '{print $1}' | tr -d '"')) | |
for vm in "${vms[@]}" | |
do | |
echo "Shutting down $vm "; | |
/usr/local/bin/VBoxManage controlvm $vm acpipowerbutton | |
done | |
runningvms=$(/usr/local/bin/VBoxManage list runningvms | wc -l | xargs) | |
# Visual feedback while waiting for the VMs to shutdown | |
while [ $runningvms -gt 0 ] | |
do | |
runningvms=$(/usr/local/bin/VBoxManage list runningvms | wc -l | xargs) | |
echo "Shutting down $runningvms VM(s)..." | |
sleep 2 | |
done | |
echo 'VM shutdown complete'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment