Last active
October 31, 2023 09:08
-
-
Save alexclifford/9822297 to your computer and use it in GitHub Desktop.
ESXi: get the IP address of a host running VMware tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Thanks for the hint guys.
I have one more version here :)
vim-cmd vmsvc/getallvms | awk '{print $1}' | grep -Ex '[0-9]{1,3}' | xargs -n 1 vim-cmd vmsvc/get.guest | grep -oE -m 1 "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"
How are you getting that to work? Busybox supports neither grep's -w or -x commands? Did you install a 3rd party grep?
@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
I started with yours and wound up using this to find IP and other info:
for i in $(vim-cmd vmsvc/getallvms | awk '{print $1}' | grep -v Vmid); do vim-cmd vmsvc/get.summary $i | grep -E ipAddress\|guestFullName\|powerState\|numCpu\|name\|memorySizeMB\|overallStatus; echo "-----"; done
Thanks for the inspiration!