Skip to content

Instantly share code, notes, and snippets.

@alexclifford
Last active October 31, 2023 09:08
Show Gist options
  • Save alexclifford/9822297 to your computer and use it in GitHub Desktop.
Save alexclifford/9822297 to your computer and use it in GitHub Desktop.
ESXi: get the IP address of a host running VMware tools
#!/bin/bash
vim-cmd vmsvc/getallvms | grep -i hostname | cut -d ' ' -f 1 | xargs vim-cmd vmsvc/get.guest | grep ipAddress | sed -n 1p | cut -d '"' -f 2
# or
ssh esxi.example.com /bin/vim-cmd vmsvc/get.guest $(ssh esxi.example.com /bin/vim-cmd vmsvc/getallvms | grep -i hostname | cut -d ' ' -f 1) | grep ipAddress | sed -n 1p | cut -d '"' -f 2
@ggb667
Copy link

ggb667 commented Aug 8, 2017

How are you getting that to work? Busybox supports neither grep's -w or -x commands? Did you install a 3rd party grep?

@shalomb
Copy link

shalomb commented Sep 6, 2017

@ggb667 - The script is running under bash - note the shebang.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment