måndag, augusti 04, 2008

Shutdown ESX 3.0.1 VM's from console

Small script for VMware ESX 3.0.1

VMShutdown.sh
--------------------
#!/bin/sh
# VMware ESX 3.0.1
# Get VM state, shutdown running VM's
# From http://www.mgeups.com/download/soft/install/linux/nsm/how_to_vmware_en_1_2.pdf
# VMware tools MUST be installed in each VM for this script to work
#
VMLIST=`/usr/bin/vmware-cmd -l`
for VM in $VMLIST
do
VMSTATE=`/usr/bin/vmware-cmd "$VM" getstate -q`
# Guest OS shutdown if VMSTATE is equal to "on"
if [ "$VMSTATE" == "on" ]
then
/usr/bin/vmware-cmd $VM stop trysoft hard
echo Waiting 10 SEC
sleep 10
fi
done
echo ----------------------------------------------------------------
echo DONE, check for errors if VM's don't have VMware tools installed
echo ----------------------------------------------------------------