You can use vmware-cmd to shut down a VMware guest. The syntax is
vmware-cmd /vmfs/volumes/datastore1/guest1/guest1.vmx stop
Powering off a VM guest is often part of a larger script, so I need to know when the guest is really down before executing the remainder of my script. The following code checks the guest’s state using getstate. If the state=1, which means it’s still running, the script waits for the shutdown to complete.
# gently power off VM vmware-cmd /vmfs/volumes/datastore1/guest1/guest1.vmx stop # check VM state # If not powered off (state=0), sleep, and recheck VM state in 15 seconds while [ ` vmware-cmd /vmfs/volumes/datastore1/guest1/guest1.vmx getstate|grep on|wc -l` -eq 1 ] do echo "Waiting for VM guest to shutdown...." sleep 15 let COUNT=COUNT+1 # check VM guest state 8 times if [ $COUNT -eq 8 ] then echo "VM guest shutdown is taking too long. Cannot shut down guest VM." skip="1" fi done
Replace datastore1 with the name of and path to your datastore. Replace guest1 with the name of your VMware guest. Tested on Vmware ESX 3.0.2.