Update esxi-shutdown2.sh

This commit is contained in:
2023-12-10 14:47:39 -06:00
parent b2f7abda3e
commit 6171d86562

View File

@@ -11,35 +11,32 @@ for VM in $VMS ; do
name=`vim-cmd vmsvc/get.config $VM | grep -i "name =" | awk '{print $3}' | head -1 | cut -d "\"" -f2` name=`vim-cmd vmsvc/get.config $VM | grep -i "name =" | awk '{print $3}' | head -1 | cut -d "\"" -f2`
echo "Powered on: $name" echo "Powered on: $name"
echo "Suspending: $name" echo "Suspending: $name"
vim-cmd vmsvc/power.suspend $VM > /dev/null & # vim-cmd vmsvc/power.suspend $VM > /dev/null &
fi fi
done done
while true ; do # while true ; do
RUNNING=0 # RUNNING=0
for VM in $VMS ; do # for VM in $VMS ; do
PWR=`vim-cmd vmsvc/power.getstate $VM | grep -v "Retrieved runtime info"` # PWR=`vim-cmd vmsvc/power.getstate $VM | grep -v "Retrieved runtime info"`
if [ "$PWR" == "Powered on" ] ; then # if [ "$PWR" == "Powered on" ] ; then
echo "Waiting..." # echo "Waiting..."
RUNNING=1 # RUNNING=1
fi # fi
done # done
if [ $RUNNING -eq 0 ] ; then # if [ $RUNNING -eq 0 ] ; then
echo "Gone..." # echo "Gone..."
break # break
fi # fi
sleep 1 # sleep 1
done # done
#
echo "Now we put the Host into maintenance mode..." # echo "Now we put the Host into maintenance mode..."
vim-cmd hostsvc/maintenance_mode_enter # vim-cmd hostsvc/maintenance_mode_enter
#
# echo "Now we suspend the Host..."
echo "Now we suspend the Host..." # esxcli system shutdown poweroff -d 10 -r "Shell initiated system shutdown"
#vim-cmd hostsvc/standby_mode_enter #
esxcli system shutdown poweroff -d 10 -r "Shell initiated system shutdown" # esxcli system maintenanceMode set -e false -t 0
esxcli system maintenanceMode set -e false -t 0
exit exit