You are here
script to start and stop VM guests on VMware server
Even VMware server 2.0 has a nice web GUI on https://localhost:8333/, you can use scripts to start and stop VM guest directly from your terminal. Before use, you have to set some hard coded parameters, like HOST_USER.
#!/bin/bash
# This script will start/stop/status VMware machine
#
# Written by Ez-Aton
# http://www.tournament.org.il/run
#
# Modified for VMware server 2.0 by doka@wepoca.net
# http://www.wepoca.net
#
#
# Hardcoded. Change to match your own settings!
# the VMware storage name
VMSTORAGE="[standard]"
# the VM guest to be started/stopped
VMGUEST="YOUR_GUEST_VM/YOUR_GUEST_VM.vmx"
# the URL of the VMware host
HOST="https://URL_OF_VMWARE_HOST:8333/sdk"
# admin user on VMware host
HOST_USER="YOUR_ADMIN"
HOST_PWD="ADMIN_PWD"
# the VMware script
VMRUN="/usr/bin/vmrun"
TIMEOUT=60
function status () {
# This function will return success if the VM is up
$VMRUN -T server -h $HOST -u $HOST_USER -p $HOST_PWD list | grep "$VMGUEST" &>/dev/null
if [[ "$?" -eq "0" ]]
then
echo "VM $VMGUEST is up"
return 0
else
echo "VM $VMGUEST is down"
return 1
fi
}
function start () {
# This function will start the VM
$VMRUN -T server -h $HOST -u $HOST_USER -p $HOST_PWD start "$VMSTORAGE $VMGUEST"
if [[ "$?" -eq "0" ]]
then
echo "VM $VMGUEST is starting"
return 0
else
echo "$VMGUEST VM failed"
return 1
fi
}
function stop () {
# This function will stop the VM
$VMRUN -T server -h $HOST -u $HOST_USER -p $HOST_PWD suspend "$VMSTORAGE $VMGUEST"
for i in `seq 1 $TIMEOUT` do
if status then
echo
else
echo "VM $VMGUEST Stopped"
return 0
fi
sleep 1 done
# $VMRUN stop "$VMGUEST" soft
$VMRUN -T server -h $HOST -u $HOST_USER -p $HOST_PWD stop "$VMSTORAGE $VMGUEST" soft
}
case "$1" in
start) start
;;
stop) stop
;;
status) status
;; esac
RET=$?
exit $RET
The original script were found on http://www.tournament.org.il/run/?p=503