script shutdown vms and host.sh

script shutdown vms and host.sh

Hey Guys ,

i've needed to write a script to shut down all virtual machines and an ESXi Host in a clean way using an UPS , so i've done some research , combined and upgraded several codes that i found in the internet , and came up with this little one ,

the script shuts downs the online VMs then puts the host in the maintenance mode , shuts down the host and disable the maintenance mode, the last step allows the host to restart normally .

i hope this helps

Attachments
Comments

Great Nouha

Thanks for the Script .

Regards

Sadiq

you are welcome

i hope it was useful for you

best regards

Hi Nouha,

Script was useful, saves time during maintenance.

Thanks

Hi Nouha,

So the principal idea of you is that; you read the status of the power input of the esxi server.

Is that right ?

with the line 

vim-cmd vmsvc/power.getstate $config | grep -i "on" > /dev/null 2<&1

STATUS=$ ?

so the first line asks to the power and waits and answer and this answer is captured  by STATUS =$ ? variable in the next line

is that right ?

so than you can start another script or some commands to turn of the vms and server itself.

I have no experience in this vmsvc but looks like worth to learn it.

In this scenario, no need to read the SNMP agent messages from UPS master agent.

Actually my second question would also be, how can we read the SNMP messages broadcastetd by UPS  ?

so than we can start some other scripts in case we catch those messages.

BR

Volkan

 

Version history
Revision #:
1 of 1
Last update:
‎10-31-2016 07:44 AM
Updated by: