esxi scripts
This commit is contained in:
39
esxi-scripts/esxi-reboot.sh
Normal file
39
esxi-scripts/esxi-reboot.sh
Normal file
@@ -0,0 +1,39 @@
|
||||
#!/bin/sh
|
||||
|
||||
|
||||
VMS=`vim-cmd vmsvc/getallvms | grep -v Vmid | awk '{print $1}'`
|
||||
for VM in $VMS ; do
|
||||
PWR=`vim-cmd vmsvc/power.getstate $VM | grep -v "Retrieved runtime info"`
|
||||
if [ "$PWR" == "Powered on" ] ; then
|
||||
name=`vim-cmd vmsvc/get.config $VM | grep -i "name =" | awk '{print $3}' | head -1 | cut -d "\"" -f2`
|
||||
echo "Powered on: $name"
|
||||
echo "Suspending: $name"
|
||||
vim-cmd vmsvc/power.suspend $VM > /dev/null &
|
||||
fi
|
||||
done
|
||||
|
||||
while true ; do
|
||||
RUNNING=0
|
||||
for VM in $VMS ; do
|
||||
PWR=`vim-cmd vmsvc/power.getstate $VM | grep -v "Retrieved runtime info"`
|
||||
if [ "$PWR" == "Powered on" ] ; then
|
||||
echo "Waiting..."
|
||||
RUNNING=1
|
||||
fi
|
||||
done
|
||||
if [ $RUNNING -eq 0 ] ; then
|
||||
echo "Gone..."
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo "Now we put the Host into maintenance mode..."
|
||||
vim-cmd hostsvc/maintenance_mode_enter
|
||||
|
||||
|
||||
esxcli system shutdown reboot -d 10 -r "Automated ESXi host reboot"
|
||||
|
||||
esxcli system maintenanceMode set -e false -t 0
|
||||
|
||||
exit
|
||||
Reference in New Issue
Block a user