I need to read the master of a network interface from a bash script.
For example, I have these two interfaces...
$ ip link show tap0 4: tap0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop master br0 state DOWN mode DEFAULT group default qlen 1000 link/ether c6:3f:96:13:02:25 brd ff:ff:ff:ff:ff:ff $ ip link show br0 3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000 link/ether 30:9c:23:75:ad:b1 brd ff:ff:ff:ff:ff:ff
Given the name of an interface I need to find the master of that interface, so
I can parse the output of
ip link show...
ip link show tap0 | head -n1 | sed 's/.*master \([^ ]*\).*/\1/' | grep -v " "
br0 (or nothing if I replace
tap0 with a device that has no master)
But I would prefer a more robust way of reading this information. Is there some kind of procfs style way to read this? Or a command that can output just the master of an interface?