UCI: Unified Configuration Interface 通用配置接口,主要用于集中控制openwrt的配置文件。web
一、uci使用的配置文件通常放置在设备上的/etc/config目录下,包括一些兼容的应用,譬如snmp,保存在/etc/config/的配置文件是已经被重写后的文件。数组
而且这些配置文件被写在RAM,而不是flash中,由于它没有必要被写在不易失的内存中,而且他们会常常改变。app
存在于/etc/config下面的文件,能够使用直接修改或者经过uci命令的方式,还有兼容的luci页面等来进行修改。配置文件被修改后,要想使配置生效,必须重启相应的进程。ide
二、uci配置文件的语法ui
uci配置文件包含了多个“config”段。this
package 'example' config 'example' 'test' option 'string' 'some value' option 'boolean' '1' list 'collection' 'first item' list 'collection' 'second item'
config 'example' 'test'
statement defines the start of a section with the type example
and the name test
. There can also be so called anonymous sections with only a type, but no name identifier. The type is important for the processing programs to decide how to treat the enclosed options.
“example”和“test”定义了一个段,段的类型为example,名字为test。也有匿名段,即只有段类型(example),木有段名称(test).spa
option 'string' 'some value'
and option 'boolean' '1'
lines define simple values within the section. Note that there are no syntactical differences between text and boolean options. Per convention, boolean options may have one of the values '0', 'no', 'off', 'false' or 'disabled' to specify a false value or '1' , 'yes', 'on', 'true' or 'enabled' to specify a true value.
“string”和“some value”组成了一对值(value)。而且对于文本和布尔型没有明确的界限命令行
list
keyword an option with multiple values is defined. All list
statements that share the same name, collection
in our example, will be combined into a single list of values with the same order as in the configuration file.
关键字“list”定义了一个数组,共用一个数组名(例如本例中的 collection),code
option
and list
statements is a convention to improve the readability of the configuration file but it's not syntactically required.
enabled
option to be disabled, is renaming the config section identifier (or type, in this case example
) to a value not recognized by the processes that uses those values. Normally a disabled_identifier
as config section type/identifier is sufficient.
一种禁止section段的方法,就是重命名section段名(或者是类型type名),总之就是使使用这个配置文件的进程识别不出来。orm
It is important to know that UCI identifiers and config file names may contain only the characters a-z
, 0-9
and _
.
uci配置文件中使用的变量只支持a-z,0-9和下划线_.
三、使用命令行修改配置文件
对于匿名段,须要加@和取第一个[0]的符号才可以正常获取和修改值。
例如:
root@hbg:/# cat /etc/config/snmpd
config agent
option agentaddress UDP:161
利用查看命令你会查看到:
root@hbg:/# uci show snmpd
snmpd.@agent[0]=agent
snmpd.@agent[0].agentaddress=UDP:161
所以你要查看agent下的值时须要使用命令:
root@hbg:/# uci get snmpd.@agent[0].agentaddress
UDP:161
root@TVWS:/#
不然会报错:
root@hbg:/# uci get snmpd.agent.agentaddress
uci: Entry not found
root@TVWS:/
来源于: http://wiki.openwrt.org/doc/uci