Just dropped the following short script in a topic on the VMTN Community. It shuts down every VM on the host and than the host itself, but it will enter maintenance mode first, just to be sure that no other vm’s get migrated to this host.
VMLIST=’vmware-cmd -l’
for config in ${VMLIST}
do
vmware-cmd $config stop trysoft
done
vimsh -n -e /hostsvc/maintenance_mode_enter
shutdown -h now
addition: thanks forbes for the trysoft addition.
Forbes Guthrie says
Hi Duncan, nice little script to have on each host.
I would add the “trysoft” to this line:
vmware-cmd ${VMLIST} stop trysoft
otherwise I think it will just send a soft power-off to the VMs. I believe the trysoft will do the same, but then hard power-off if the soft doesn’t work.
Forbes.
Andrew Gallop says
Hi Duncan,
Apologies if this is a somewhat uneducated question. Could this script be initiated by UPS software to power down the VMs and host in the event of a power failure?
Regards,
Andrew
Duncan Epping says
Yeah why not. But I wouldn’t place it into maintenance mode because VM’s will not startup when the server is in maintenance mode, or you would have to script a ” leave maintenance mode” .
Christos Myrsakis says
hi guys
how do i execute this script? do i save it as a vbs and run it? How can i launch this from a batch file?
Finally i didn’t quite understand what are the changes required ti implment Forbes’ suggestion.
Many Thanks
Christos
Duncan says
These changes already have been made, and its a bash script so run it from the service console
Doug says
Scripting help. When using Remote CLI I receive “Can’t modify constant item in scalar assignment at line 2”. Any ideas?
asdf says
not working
[2009-02-11 23:29:51.328 ‘App’ 3076468864 info] Current working directory: /usr/lib/vmware/hostd
[2009-02-11 23:29:51.329 ‘BaseLibs’ 3076468864 info] HOSTINFO: Seeing AMD CPU, numCoresPerCPU 2 numThreadsPerCore 1.
[2009-02-11 23:29:51.332 ‘BaseLibs’ 3076468864 info] HOSTINFO: hyperthreading disabled, setting number of threads per core to 1.
[2009-02-11 23:29:51.332 ‘BaseLibs’ 3076468864 info] HOSTINFO: This machine has 4 physical CPUS, 8 total cores, and 8 logical CPUs.
[2009-02-11 23:29:51.429 ‘BaseLibs’ 3076468864 info] System libcrypto.so.0.9.7 library is older than our library (90701F < 90709F)
[2009-02-11 23:29:51.429 ‘App’ 3076468864 info] Vmacore::InitSSL: doVersionCheck = true, handshakeTimeoutUs = 120000000
Failed to connect: 514 Error connecting to hostd-vmdb service instance.
Not connected.
Not connected.
Duncan Epping says
i’ve updated the scripts, please try again…
uli says
Hi to all,
the script is ok but my virtual machines has a space in the name and the script does not works.
Someone can help me?
Thanks
goomior says
uli, try this one:
vmware-cmd -l | while read i
do
vmware-cmd $i stop trysoft
done
You may also use “if” and “vmware-cmd $i getstate” to prevent powering of already powered-off machines.
Vamsi says
Hello All,
Is there any way to stop only specific vms from the list of input file?
Thanks