So I wanted to try to extract just the IP address of a named network adapter using bash. There are lots of ways to do this, but it turns out that the linux ip command supports output to JSON. This gets me thinking jq. After testing on Manjaro and Amazon Linux 2, this is the most reliable command I found.
ip -4 -j a | jq -r '.[] | select(.ifname | contains("eth0")) | .addr_info[].local'
Obviously the interface name is going to be different on different systems
No comments:
Post a Comment