Livy
March 8, 2020, 9:44am
1
We can access anonymous sections through an array, for example:
uci show network.@switch[0]
uci show fstab.@mount[-1]
How do I loop through these arrays? At least how can I get the array size?
This literally works but it is stupid:
index=0;
uci show fstab.@mount[$index] > /dev/null 2>&1;
while [ $? -eq 0 ]
do
index=$((index + 1));
# Your code goes here.
fi
2 Likes
I'm doing
i=0
while uci get bla.@user[$i] &> /dev/null ; do
i=$((i+1));
done
1 Like
But an upstream solution would be nice.
Ah, you are right! But not sure if I can remove something again. For example I have this hotplug.d script:
openwrt:master
← PolynomialDivision:wg-installer-hotplug
opened 07:53PM - 07 Feb 21 UTC
Nice functions.sh but i cant get it to echo the configuration.
#!/bin/sh
. /lib/functions.sh
config_get network.@wireguard_wggs[*].allowed_ips
does nothing.
I am sure i dont understand something here .
Can someone give me a hint, again ?
I need to iterate through all ips to find an unused one.
I could use :
i=0
while uci get bla.@user[$i] &> /dev/null ; do
i=$((i+1));
done
but i like to learn it the openwrt style right away. I am sure if i unsderstand the logic behind the functions.sh i made a big step to program better shell scripts for openwrt.
Thank you guys.
THIS LOOKS PROMISSING:
yourCustomFunction() {
config_get nameVar "$1" 'name'
config_get ipVar "$1" 'ip'
}
. /lib/functions.sh
config_load dhcp
config_foreach yourCustomFunction 'host'
stangri
February 23, 2021, 10:22pm
7
eliasmagnus:
Nice functions.sh but i cant get it to echo the configuration.
#!/bin/sh
. /lib/functions.sh
config_get network.@wireguard_wggs[*].allowed_ips
does nothing.
I am sure i dont understand something here .
Have you read this: https://openwrt.org/docs/guide-developer/config-scripting ?
1 Like
system
Closed
March 5, 2021, 10:23pm
8
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.