uci是openwrt上配置操作的接口,不管是自动化的shell脚本,还是使用luci来二次开发配置界面,都会用到这部分知识。 uci提供了lua, shell, c接口,这里主要用到了前两种

shell接口

文档地址,增删改查都有,这里简单使用下。

下面的配置为例子

root@xCloud:~# cat /etc/config/test

config test 'abc'
option test_var2 'value22'
option test_var 'value11'

config tt1
option name 'lzz'

查看配置

root@xCloud:~# uci show test
test.abc=test
test.abc.test_var2='value22'
test.abc.test_var='value11'
test.@tt1[0]=tt1
test.@tt1[0].name='lzz'

显示配置的文本

root@xCloud:~# uci export test
package test

config test 'abc'
option test_var2 'value22'
option test_var 'good'

config tt1
option name 'lzz'

修改一个配置项的值

oot@xCloud:~# uci set test.abc.test_var="good"
root@xCloud:~# uci commit test
root@xCloud:~# uci show test.abc.test_var
test.abc.test_var='good'

获取一个配置项的值

root@xCloud:~# uci get test.abc.test_var
good
root@xCloud:~# uci show test.abc.test_var
test.abc.test_var='good'
root@xCloud:~# uci show test.@tt1[0].name
test.cfg03af7e.name='lzz'
root@xCloud:~# uci get test.@tt1[0].name
lzz

lua接口

通过下面的例子理解

#!/usr/bin/lua
print("Testing start..")
require("uci")

-- Get asection type or an option
x =uci.cursor()
a =x:get("test", "abc", "test_var")

if a == nil then
print("can't found the config file")
return
else
print(a)
end

x:set("test", "abc", "test_var", "value11")
tt1 = x:add("test", "tt1")
x:set("test", tt1, "name", "lzz")

-- Getthe configuration directory
b =x:get_confdir()
print(b)

-- Getall sections of a config or all values of a section
d = x:get_all("test", "abc")
print("config test abc")
print(d)
print(d["test_var"])
print(d["test_var2"])

-- loop a config
x:foreach("test", "tt1", function(s)
    print("----")
    for k,v in pairs(s) do
print(k..":"..tostring(v))
    end
end)

-- discard changes, that have not been commited
-- x:revert("test")

-- commit changes
x:commit("test")

--[[
/etc/config/test
config 'test' 'abc'
    option 'test_var' 'value'
    option 'test_var2' 'value22'
]]

代码最后的注释是测试config的路径和内容

[openwrt] uci 的shell和lua接口的更多相关文章

  1. 将iconv编译成lua接口

    前一篇博文说了.在cocos2dx中怎么样使用iconv转码,这节我们将上一节中写的转码函数,做成一个lua接口.在lua脚本中使用. 网上能够下载到luaconv.可是编译的时候总是报错,所以自己写 ...

  2. 使用luabind绑定box2d的lua接口

    最近在使用luabind绑定box2d的lua接口,发现不少问题.写在这里与大家分享. 1. body,fixture,joint的userdata.box2d的userdata的数据类型是void* ...

  3. OpenWrt Web 开发 LuCI框架 lua语言

    LuCI作为“FFLuCI”诞生于2008年3月份,目的是为OpenWrt固件从 Whiterussian 到 Kamikaze实现快速配置接口.Lua是一个小巧的脚本语言,很容易嵌入其它语言.轻量级 ...

  4. openwrt uci

    UCI: Unified Configuration Interface 通用配置接口,主要用于集中控制openwrt的配置文件. 1.uci使用的配置文件一般放置在设备上的/etc/config目录 ...

  5. OpenWRT UCI命令实现无线中继

    本文主要功能主要是利用OpenWRT系统uci命令实现无线中继,主要是利用uci程序修改/etc/congfig/目录下的配置文件.实现步骤如下主要分为以下几步: 1) 安装 relayd (opkg ...

  6. shell判断USB接口是否有设备插入

    #/bin/sh usb_num=$(cat /proc/scsi/scsi | grep "Vendor" | wc -l)if [ $usb_num = 2 ];then    ...

  7. shell执行lua脚本传参数

    #lua test.lua 2 5arg[0]= test.lua arg[1]= 2arg[2]= 5 if arg[1] and arg[1] == "2" then prin ...

  8. 通过shell调用rtx接口

    本脚本可获取服务器Site值和服务器ip,执行之后可通过RTX推送系统消息 脚本例子如下: #!/bin/bash function alarm(){ user="$1" cont ...

  9. OpenWrt的UCI系统

    http://wiki.openwrt.org/doc/uci UCI是Unified Configuration Interface的缩写,翻译成中文就是统一配置接口,用途就是为OpenWrt提供一 ...

随机推荐

  1. ●BZOJ 1096 [ZJOI2007]仓库建设

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1096 题解: 斜率优化DP $(d_i:i 位置到1位置的距离,p_i:i位置的成品数量,c ...

  2. hdu 5441 (并查集)

    题意:给你n个点,m条边构成无向图.q个询问,每次一个值,求有多少条路,路中的边权都小于这个值 a->b 和 b->a算两种 思路:把权值从小到大排序,询问从小到大排序,如果相连则用并查集 ...

  3. [Codeforces]813F Bipartite Checking

    往期题目补档.既然被选为了经典题就拿来写一写. Description 给定一张含有n个点的无向图,一开始图中没有任何边.依次给出q次操作,每次操作给出两个点“x y”,若x和y之间没有边相连,则连上 ...

  4. python 类的特殊成员方法

    __doc__ # 输出类的描述信息 __module__ # 表示当前操作的对象在那个模块 __class__ # 表示当前操作的对象的类是什么 __init__ # 构造方法,通过类创建对象是,自 ...

  5. Java8-理解Colloctor

    上一节学习了Java8中比较常用的内置collector的用法.接下来就来理解下collector的组成. Collector定义 Collector接口包含了一系列方法,为实现具体的归约操作(即收集 ...

  6. 15. 3Sum(中等)

    Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...

  7. 关于go语言的通道

    1.记一次gorountine导致的泄漏 在项目中使用https://github.com/deckarep/golang-set这个三方包造成了gorountine泄漏.先来看一下这个包的迭代器设置 ...

  8. Go 语言基础语法

    Go 标记 Go 程序可以由多个标记组成,可以是关键字,标识符,常量,字符串,符号.如以下 GO 语句由 6 个标记组成: fmt.Println("Hello, World!") ...

  9. 为什么《Dive into Python》不值得推荐

    2010 年 5 月 5 日更新:我翻译了一篇<<Dive Into Python>非死不可>作为对本文观点的进一步支持和对评论的回复,请见:http://blog.csdn. ...

  10. Freemarker商品详情页静态化服务调用处理

    --------------------------------------------------------------------------------------------- [版权申明: ...