Hi,
I have created a script to show on the swtich with opentwrt (zyxel 1900-10HP) the interfaces, state, speed, and vlan config. I have with the last one 1 issue. I get the vlans, only the first vlan, I can get it script for the correct.
I use the command bridge vlan show dev interface.
I should get for interface lan1 this
root@GS1900-10HP:~# bridge vlan show dev lan1
port vlan-id
lan1 10
70
90
99 PVID Egress Untagged
100
Running the script I get this, and missing vlan 10
root@GS1900-10HP:~# ./lan1.sh
LAN-port info
| Port | Speed | State | VLANS |
|-----------------|------------|-----------------|--------------------------------|
| lan1 | 100Mb/s | connected | 70,90,99(u),100 |
| lan10 | --- | notconnected | |
| lan2 | 1000Mb/s | connected | 70,90,99(u),100 |
| lan3 | 1000Mb/s | connected | 70,90,99(u),100 |
| lan4 | 1000Mb/s | connected | |
| lan5 | 1000Mb/s | connected | 70,90,99(u),100 |
| lan6 | --- | notconnected | 70,90,99(u),100 |
| lan7 | 1000Mb/s | connected | |
| lan8 | 1000Mb/s | connected | 70,90,99(u),100 |
| lan9 | 1000Mb/s | notconnected | |
I tried resolving it with chatgpt, but didn't work. Hopefully someone like the script and will help to solve the issue.
#!/bin/sh
print_row() {
printf "| %-15s | %-10s | %-15s | %-30s |\n" "$1" "$2" "$3" "$4"
}
echo "LAN-port info"
echo ""
interfaces=$(ls /sys/class/net | grep -E '^lan')
printf "| %-15s | %-10s | %-15s | %-30s |\n" "Port" "Speed" "State" "VLANS"
printf "|-----------------|------------|-----------------|--------------------------------|\n"
for interface in $interfaces; do
speed=$(ethtool $interface | grep "Speed:" | awk '{print $2}')
if [ "$speed" = "Unknown!" ]; then
speed="---"
fi
status=$(cat /sys/class/net/$interface/operstate)
vlan_config=$(bridge vlan show dev "$interface" | awk -v intf="$interface" "{ if (\$1 == intf) { flag=1; next } if (flag) { if (\$NF == \"Untagged\") { printf \"%s(u),\", \$1 } else { printf \"%s,\", \$1 } } }" | sed 's/,$//')
vlan_config=${vlan_config%,} # Verwijder de laatste komma
if [ "$status" = "up" ]; then
status="connected"
else
status="notconnected"
fi
print_row "$interface" "$speed" "$status" "$vlan_config"
done