KB ID 0000279
Problem
I was asked the question last week “How do I shutdown my ESX server remotely from script”. The client had a temperature sensor in their server room and wanted to shutdown their ESX host if it got too hot, all his Windows servers got sent an SNMP trap from the temperature sensor, and that fires off a script to shut down the Windows servers. But this left the ESX host up and running.
Solution
I drew a blank on getting a shell script to fire when an SNMP trap is received on ESX, but there’s nothing to stop me adding a line to one of the Windows server scripts that would shut down the ESX server.
1. Firstly get all your Guest VM’s to shutdown automatically when the host is shut down > In the VI client > Select the host > Configuration > Virtual Machine Startup/Shutdown > Properties.
2. Tick the box marked “Allow virtual machines to start and stop automatically with the system” > Change the “Shutdown Action” option from “Power Off” to “Guest Shutdown”.
3. Select Each guest VM and click the “Move Up” button so that are all in the automatic startup section > OK.
WARNING – this is not supported on ESX4 for guest VM’s in a High Availability cluster. (page 22).
4. I’m going to shutdown using the root account, for this to work you need to allow SSH access to the root user see HERE.
5. Download a copy of plink.exe and put it in the same directory as your script (or the system32 directory on the windows machine).
6. Add the following line to the bottom of your script,
[box]plink -ssh root@172.16.254.209 -pw password123 poweroff -p[/box]
Note: where password123 is the root password, and 172.16.254.209 is the IP of the ESX server.
7. When the line is executed, the guest VM’s will shut down, then the ESX Server will power off.
In the VI client you will see the guests shutting down.
Related Articles, References, Credits, or External Links
NA