Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #!/bin/bash
  2. # script to shutdown all running VirtualBox vms
  3. # matt@fastforwardtechnology.co.uk
  4.  
  5. # function to shutdown a running vm
  6.  
  7. shutdown_vm()
  8. {
  9. VMNAME=$1
  10. VMSTATE="running"
  11. I=0
  12. echo -n "Shutting down VirtualBox VM: $VMNAME"
  13.  
  14. VBoxManage controlvm $VMNAME acpipowerbutton
  15.  
  16. # loop until state is poweroff
  17. while [ $VMSTATE != "poweroff" ] && (( $I < 60 )); do
  18. echo -n "."
  19. (( I++ ))
  20. sleep 1
  21. VMINFO=$(VBoxManage showvminfo $VMNAME --machinereadable | sed -n -e '/^VMState=/p')
  22. VMSTATE=$(echo $VMINFO | cut -f2 -d'"')
  23. done
  24.  
  25. if [ $VMSTATE == "poweroff" ]; then
  26. echo -en "done\n"
  27. else
  28. echo -en "failed\n"
  29. fi
  30. }
  31.  
  32. # loop through running vms
  33. VBoxManage list runningvms | while read NAME; do
  34. CUTNAME=$(echo $NAME | cut -f2 -d'"')
  35. shutdown_vm $CUTNAME
  36. done
  37.  
  38. echo ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement