esx-halt: shutdown VMWare ESXi from ssh

Long time no post – again – I hope this is the last time and I can be a little more prolific :) Anyway today I want to share a little script that I hacked to shutdown an ESXi (with the free license) host remotely, shutting down in a safely form all the VMs inside it. This could be quite usefull (and in fact it’s why I wrote it), if you want to shutdown ESXi from an UPS daemon when lights go out, and you cannot afford a complete ESXi license, so you’re running the free edition.
The script can be found here at GitHub

and it’s written in bash (I use bash4 but it should run on lesser versions too). On the server side, it works with VMWare ESXi 4.x.

Any question, patch or bug report are warmly welcome :)


4 thoughts on “esx-halt: shutdown VMWare ESXi from ssh

  1. Hey,

    Thank you for your script!
    I tried it, but it doesn’t work.
    Is there anything to change in the script? What about ssh password authentification?

    Thank you anyway

    • hello! thanks for your feedback… what’s the problem exactly? Authentication was intentionally left out, you must be already able to ssh into the esxi host passwordless (I’ll try to specify it more clearly in the README). If you have problem with ssh authentication, I can write another mini-howto, no problem!

  2. Very nice work!

    I had to add a grep “vmx” to the lines where it gets virtual machine names couse if you add annotations to the machine including return characters it shows in vim-cmd vmsvc/getallvms as new lines

    So line 47:
    $SSH_CMD “vim-cmd vmsvc/getallvms”|tail -n +2 | grep ‘.vmx’ | grep -v “${SHUTDOWNER}”|awk ‘{print $1}’|while read vmid

    And line 67:
    $SSH_CMD “vim-cmd vmsvc/getallvms”|tail -n +2 | grep ‘.vmx’ | grep -v “${SHUTDOWNER}”|awk ‘{print $1}’|while read vmid

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s