Whatever I do this does not help.
echo "starting app"
config_get proto dnsmasq nonegcache
echo "Value is $proto"
$proto is always displayed blank. I tried with bool setting default value to 1, it always displays 1 while config file has
option domainneeded '1'
option boguspriv '1'
option filterwin2k '0'
option localise_queries '1'
option rebind_protection '1'
option rebind_localhost '1'
option local '/lan/'
option domain 'lan'
option expandhosts '1'
option nonegcache '0'
option authoritative '1'
option readethers '1'
option leasefile '/tmp/dhcp.leases'
option resolvfile '/tmp/resolv.conf.auto'
option localservice '1'
config_get doesn't look right...
Please show how it must look right. I need to take one option from the config file, and then update this option. That's all. Doc says I must supply variable, section name and option name. This
config_get proto dnsmasq nonegcache has everything it needs?
Look at the example in the docs and how it's formatted.
Quotes? They make no difference. Can you tell me please what is wrong with my code?
Don't know how you get the cfg id from the command line, but this works for me:
config_get test cfg01411c nonegcache
This hints at the answer.
dnsmasq section in the config is of "type"
dnsmasq, but it is not "named"
dnsmasq. A subtle but important difference.
If you can determine the actual name of the section (which will be
cfgxxxxx as per dave's response) ahead of time, you can access it directly. Otherwise you will need to iterate through all sections of "type"
dnsmasq, which is where config_foreach comes in. In most (all?) cases, there will be only a single dnsmasq section, so you shouldn't have to handle any weird or unexpected behaviour.
@lantis1008 @dave14305 thank you very much for the information. Before asking for help here I spent several hours trying to get it working, reviewed a lot of examples (including live system) and my example I laid out above is based on what I have seen in those examples. I also have seen lots of mistakes in real files like performing
include /lib/functions (without .sh) which I believe must not work properly (I did not test myself). I wonder why system does not display errors for such things, and does not have any 'debug' mode - it causes lots of problems in seemingly working scripts.
Will let you know on my results.
Finally I was not able to properly code using config_get. And switched to UCI. It has much better documentation, and I was able to test using CLI. As sections of my config file are hardcoded, I can address variable using fixed path. As I understand I will have to use UCI anyway because seen somewhere else that config_set is buggy and I must use
uci set for proper and reliable result.