Skip to content

Commit

Permalink
Add script to batch start VMs
Browse files Browse the repository at this point in the history
  • Loading branch information
lattera committed Oct 23, 2012
1 parent d49d93a commit 27bf178
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
*.txt
nohup.out
49 changes: 49 additions & 0 deletions vbox.sh
@@ -0,0 +1,49 @@
#!/usr/local/bin/bash

cd $(dirname ${0})

startport=5901

shutdown_vms ()
{
needsleep=0

for vm in $(VBoxManage list runningvms | awk '{print $3};'); do
echo "[+] Stopping ${vm}"
VBoxManage controlvm ${vm} acpipowerbutton
needsleep=1
done

if [ ${needsleep} == 1 ]; then
echo "[+] One or more VMs needed to be powered off. Sleeping for 60 seconds."
sleep 60
fi
}

if [ ! -f "vm_list.txt" ]; then
echo "[-] Please add each VM on its own line in vm_list.txt"
exit 1
fi

case $1 in
start|restart)
shutdown_vms
OIFS=$IFS
IFS=$'\n'

for vm in `cat vm_list.txt`; do
echo "[+] Starting ${vm} with VNC port ${startport}"
nohup VBoxHeadless -s "${vm}" -n -m ${startport} &
startport=$((startport+1))
done

IFS=$OIFS
;;
stop)
shutdown_vms
;;
*)
;;
esac

exit 0

0 comments on commit 27bf178

Please sign in to comment.