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. 【USACO11NOV】牛的阵容Cow Lineup 尺取法+哈希

    题目描述 Farmer John has hired a professional photographer to take a picture of some of his cows. Since ...

  2. 【bzoj4569 scoi2016】萌萌哒

    题目描述 一个长度为n的大数,用S1S2S3...Sn表示,其中Si表示数的第i位,S1是数的最高位,告诉你一些限制条件,每个条件表示为四个数,l1,r1,l2,r2,即两个长度相同的区间,表示子串S ...

  3. ubuntu 系统应用安装方式

    转载   ubuntu系统软件安装 来源:http://www.linuxidc.com/Linux/2011-02/32211.htm 首先说明一下 ubuntu 的软件安装大概有几种方式:1. d ...

  4. Machine Learning From Scratch-从头开始机器学习

    Python implementations of some of the fundamental Machine Learning models and algorithms from scratc ...

  5. 找到一个牛的一逼的,超简易ssm和ssh的学习网址

    http://how2j.cn 蛋疼的是,我早就用springboot了!不过,可以给公司新人看.

  6. MySQL数据库常用操作入门

    一.MySQL MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle旗下产品.在WEB应用方面,MySQL是最好的RDBMS应用软件.MySQL体积小.速度快.总 ...

  7. linux 3.10 缺页异常(TLB_invalid)通用处理框架

  8. PHP Zip File 函数

    通过 PHP 中的相关函数,你可以实现 zip 文件的解压缩操作! PHP Zip File 简介 Zip File 函数允许您读取压缩文件. 安装 如需在服务器上运行 Zip File 函数,必须安 ...

  9. Gradle 1.12用户指南翻译——第46章. Java 库发布插件

    本文由CSDN博客貌似掉线翻译,其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Githu ...

  10. Lucene查询结果高亮

    检索结果高亮 实现效果: 核心代码 package ucas.ir.lucene; import java.io.File; import java.io.IOException; import ja ...