Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # script to shutdown all running VirtualBox vms
- # matt@fastforwardtechnology.co.uk
- # function to shutdown a running vm
- shutdown_vm()
- {
- VMNAME=$1
- VMSTATE="running"
- I=0
- echo -n "Shutting down VirtualBox VM: $VMNAME"
- VBoxManage controlvm $VMNAME acpipowerbutton
- # loop until state is poweroff
- while [ $VMSTATE != "poweroff" ] && (( $I < 60 )); do
- echo -n "."
- (( I++ ))
- sleep 1
- VMINFO=$(VBoxManage showvminfo $VMNAME --machinereadable | sed -n -e '/^VMState=/p')
- VMSTATE=$(echo $VMINFO | cut -f2 -d'"')
- done
- if [ $VMSTATE == "poweroff" ]; then
- echo -en "done\n"
- else
- echo -en "failed\n"
- fi
- }
- # loop through running vms
- VBoxManage list runningvms | while read NAME; do
- CUTNAME=$(echo $NAME | cut -f2 -d'"')
- shutdown_vm $CUTNAME
- done
- echo ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement