VMware Cloud Community
Eds89
Enthusiast
Enthusiast
Jump to solution

Help scripting graceful shutdown of VMs via SSH

Hello,

I would like to script the graceful shutdown of my running VMs by connecting to my host using SSH and running some commands.

I have the appropriate command to shutdown a VM gracefully as:

vim-cmd vmsvc/power.shutdown VMID

What I need assistance with, is to try and use:

vim-cmd vmsvc/getallvms

To try and only return a list of VMs currently running, and to also filter out one specific VM (which the script will effectively be run from).

Is there a way to either do this directly in the commands, or can I capture the output of vim-cmd and interpret it in a script to achieve this?

Cheers

Eds

0 Kudos
1 Solution

Accepted Solutions
Eds89
Enthusiast
Enthusiast
Jump to solution

I got a shell script created and stored on my ESXi host.

Not the greatest, but it can be found on this Stackoverflow question for reference:

shell - Linux - trim table of text and store values as variables - Stack Overflow

The host gets connected to via SSH, and this script is run, shutting down all running VMs.

Eds

View solution in original post

0 Kudos
1 Reply
Eds89
Enthusiast
Enthusiast
Jump to solution

I got a shell script created and stored on my ESXi host.

Not the greatest, but it can be found on this Stackoverflow question for reference:

shell - Linux - trim table of text and store values as variables - Stack Overflow

The host gets connected to via SSH, and this script is run, shutting down all running VMs.

Eds

0 Kudos