Created
July 15, 2017 17:53
-
-
Save pschmitt/b45490e2304b9302ea767ec0340b5705 to your computer and use it in GitHub Desktop.
Get the IP address of a VM hosted on Proxmox
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
#!/usr/bin/env bash | |
usage() { | |
echo "$(basename $0) VM" | |
} | |
get_vm_id() { | |
qm list | awk '/'"${1}"'/ { print $1 }' | |
} | |
get_vm_mac_addr() { | |
qm config "$1" | awk '/net0/ { print tolower($2) }' | \ | |
sed -r 's/virtio=(.*),.*/\1/g' | |
} | |
get_ip_from_mac_arp() { | |
arp -an | awk '/'"$1"'/ { print $2 }' | sed 's/(\(.*\))/\1/g' | |
} | |
if [[ -z "$1" ]] | |
then | |
usage | |
exit 2 | |
fi | |
case "$1" in | |
-h|--help|help) | |
usage | |
exit 0 | |
esac | |
VM_ID=$(get_vm_id $1) | |
if [[ -z "$VM_ID" ]] | |
then | |
echo "Could not determine VM ID for $1" | |
exit 3 | |
fi | |
VM_MAC_ADDR=$(get_vm_mac_addr "$VM_ID") | |
if [[ -z "$VM_MAC_ADDR" ]] | |
then | |
echo "Could not determine VM MAC address for $1 ($VM_ID)" | |
exit 3 | |
fi | |
get_ip_from_mac_arp "$VM_MAC_ADDR" | |
# vim: set et ts=2 sw=2 ft=bash : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
that is greatful,but how can i get ip from vm used lxc