openwrt 之通过uci 设置参数

在openwrt中, 默认一种配置文件,默认的路径/etc/config,在这里面的所有配置文件如需要修改只需使用uci 这个指令来修改。

以下uci 指令参数:

root@xxxx:~# uci 
Usage: uci [<options>] <command> [<arguments>]
Commands:
batch
export     [<config>]
import     [<config>]
changes    [<config>]
commit     [<config>]
add        <config> <section-type>
add_list   <config>.<section>.<option>=<string>
del_list   <config>.<section>.<option>=<string>
show       [<config>[.<section>[.<option>]]]
get        <config>.<section>[.<option>]
set        <config>.<section>[.<option>]=<value>
delete     <config>[.<section>[[.<option>][=<id>]]]
rename     <config>.<section>[.<option>]=<name>
revert     <config>[.<section>[.<option>]]

reorder    <config>.<section>=<position>

举个栗子来认识uci 是如何修改配置文件的,here we go!

配置文件 /etc/config/herewego.conf (mqtt的配置参数)的内容如下:

config lagent_0
option mqtt_port '8883'
option cafile '/etc/lagent/rootCA.crt'
option certfile '/etc/lagent/cert.pem'
option keyfile '/etc/lagent/privkey.pem'
option model 'lds.gateway.g151'

config lagent_1
option mqtt_port '8883'
option cafile '/etc/lagent/rootCA.crt'
option certfile '/etc/lagent/cert.pem'
option keyfile '/etc/lagent/privkey.pem'

option model 'lds.gateway.g151'

1, 修改lagent_0的下model参数 值: uci set herewego.@lagent_0[-1].model=lds.gateway.g111  

    在herewego.conf这个文件中有两个config 参数lagent_0, lagent_1 , uci 里面读取到这个文件后, 会将文件中的config参数保存到结构体链表中,默认数据索引是从-1开始, 同理修改lagent_1中的参数时使用索引0 ,  uci set herewego.@lagent_1[0].model=lds.gateway.g111 


2, 在lagent_0中增加参数did  : uci add herewego.@lagent_0[-1].did=xxxxxxxxxxxx

3,  删除lagent_0中的did : uci delete herewego.@lagent_0[-1].did

4, 获取lagent_0中的did : uci get herewego.@lagent_0[-1].did

以上为增删改查基本应用。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值