I want to bring a bridge down only when the last port is removed and so I have this somewhat hokey check to do it
brctl show looks awkward to parse to get the information out and doesn't feel much better than what I have below. Is there a cleaner method?
brctl_count_if()
{
local BRIDGE=$1
if [ ! -d /sys/devices/virtual/net/$BRIDGE ]; then
echo 0
return
fi
/bin/ls -1 /sys/devices/virtual/net/$BRIDGE/brif 2>/dev/null | wc -l
}