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. C# winform中自定义精确定时器(经测试稳定可靠)

    原C#的定时器时间越长,误差越大. 在主动请求设备数据的使用,使用C#的几种自带定时器导致每天都会丢失几条数据. 经测试使用自定义的定时器可完全解决此问题. 使用方法: MillisecondTime ...

  2. PySC2是DeepMind的“星际争霸II学习环境”(SC2LE)的Python组件

    PySC2是DeepMind的"星际争霸II学习环境"(SC2LE)的Python组件. 它暴露了暴雪娱乐公司的星际争霸II机器学习API作为Python RL环境. 这是Deep ...

  3. Mysql锁机制--概念、分类及基础命令

    Mysql 系列文章主页 =============== 1 概念 在 Java 程序中,当多线程并发访问某个资源的时候,如果有非线程安全的操作,那么需要通过加锁来保护之.同理,在 Mysql 中,如 ...

  4. RxSwift 系列(八) -- Error Handing Operators

    前言 本篇文章我们将学习RxSwift中的错误处理,包括: catchErrorJustReturn catchError retry retry(_:) catchErrorJustReturn 遇 ...

  5. 剖析Vue原理&实现双向绑定MVVM

    转自:http://www.w3cmark.com/2016/496.html 本文能帮你做什么? 1.了解vue的双向数据绑定原理以及核心代码模块 2.缓解好奇心的同时了解如何实现双向绑定 为了便于 ...

  6. 注解式Schedule配置定时任务

    @Component public class ScheduledTasks { @Autowired private ActivityService activityService; // 1000 ...

  7. electron-vue 初体验

    注意事项 首先确保node和npm是最新版本 避免使用镜像(我淘宝镜像安装有报错现象) 避免window的一些坑 若上一项检查完成,我们可以继续设置所需的构建工具.使用 windows-build-t ...

  8. Python小代码_5_二维矩阵转置

    使用列表推导式实现二维矩阵转置 matrix = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] print(matrix) matrix_t = [[ro ...

  9. Hadoop系列:(一)hdfs文件系统的基本操作

    可以执行所有常用的Linux文件操作命令(读取文件,新建文件,移动文件,删除文件,列表文件等) 1.help命令获取没个命令的帮助 [cloudera@quickstart ~]$ hadoop fs ...

  10. Java不走弯路教程(前言)

    本教程的程序基于Windows开发,所以你需要有一台安装Windows操作系统的电脑. 前言本教程将带你完成Java的初学和WEB框架的开发,学完本教程,你将完成对Java的入门并且对下一步不再迷茫. ...