How to get index of network configs using uci command

Hi,
I want to get all the static routes added in my router & need to call "network restart" to reflect the static routes in console. I'm using a shell script to do it. I'm facing trouble in accessing the index of "route" in "network" configuration via using uci. Here's my code -

route_num=`ubus call network.interface.lan status | jsonfilter -e '@["route"]' | grep -o "mask" | wc -l`
                      cnt=0

                      for i in {0..$route_num}; do
                              dest=`uci -q get network.@route[].dest`
                              state=`uci -q get network.@route[].disabled`
                              if [ "$dest" != "" ] && [ "$state" = "0" ]; then
                                      cnt=$((cnt + 1))
                              fi
                      done
                      
                      if [ "$cnt" -gt 0 ]; then
                              touch /tmp/route_updated
                              echo "updated route" >> /tmp/route_updated
                              /etc/init.d/network restart
                      fi

Pls suggest the right way to access indexes of "static route". Thanks in advance.

Have you started using official OpenWRT firmware rather than a third-party modified version?

yes, it's an official openwrt FW - 21.02.

for i in $(uci show network | grep \=route | cut -d "[" -f2 | cut -d "]" -f1); do uci get network.@route[$i].target; done
1 Like

It works fine.... Thanks a lot @pavelgl

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.