[openwrt] uci 的shell和lua接口
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接口的更多相关文章
- 将iconv编译成lua接口
前一篇博文说了.在cocos2dx中怎么样使用iconv转码,这节我们将上一节中写的转码函数,做成一个lua接口.在lua脚本中使用. 网上能够下载到luaconv.可是编译的时候总是报错,所以自己写 ...
- 使用luabind绑定box2d的lua接口
最近在使用luabind绑定box2d的lua接口,发现不少问题.写在这里与大家分享. 1. body,fixture,joint的userdata.box2d的userdata的数据类型是void* ...
- OpenWrt Web 开发 LuCI框架 lua语言
LuCI作为“FFLuCI”诞生于2008年3月份,目的是为OpenWrt固件从 Whiterussian 到 Kamikaze实现快速配置接口.Lua是一个小巧的脚本语言,很容易嵌入其它语言.轻量级 ...
- openwrt uci
UCI: Unified Configuration Interface 通用配置接口,主要用于集中控制openwrt的配置文件. 1.uci使用的配置文件一般放置在设备上的/etc/config目录 ...
- OpenWRT UCI命令实现无线中继
本文主要功能主要是利用OpenWRT系统uci命令实现无线中继,主要是利用uci程序修改/etc/congfig/目录下的配置文件.实现步骤如下主要分为以下几步: 1) 安装 relayd (opkg ...
- shell判断USB接口是否有设备插入
#/bin/sh usb_num=$(cat /proc/scsi/scsi | grep "Vendor" | wc -l)if [ $usb_num = 2 ];then ...
- shell执行lua脚本传参数
#lua test.lua 2 5arg[0]= test.lua arg[1]= 2arg[2]= 5 if arg[1] and arg[1] == "2" then prin ...
- 通过shell调用rtx接口
本脚本可获取服务器Site值和服务器ip,执行之后可通过RTX推送系统消息 脚本例子如下: #!/bin/bash function alarm(){ user="$1" cont ...
- OpenWrt的UCI系统
http://wiki.openwrt.org/doc/uci UCI是Unified Configuration Interface的缩写,翻译成中文就是统一配置接口,用途就是为OpenWrt提供一 ...
随机推荐
- 【USACO】AC自动机
Description 对,这就是裸的AC自动机. 要求:在规定时间内统计出模版字符串在文本中出现的次数. Input 第一行:模版字符串的个数N. 第2->N+1行:N个字符串.(每个模版字符 ...
- Python中模块之sys的功能介绍
sys模块的功能介绍 1. sys的变量 argv 命令行参数 方法:sys.argv 返回值:list 例如:test1.py文件中有两句语句1.import sys 2.print(sys.arg ...
- Serpent.AI – 游戏代理框架(Python)
Serpent.AI - 游戏代理框架(Python) Serpent.AI是一个简单而强大的新颖框架,可帮助开发人员创建游戏代理.将您拥有的任何视频游戏变成一个成熟的实验的沙箱环境,所有这些都是熟悉 ...
- 记一次sql优化——left join不走索引问题
sql一执行就卡住,然后就...杀进程了 看了一下表的大小 第一反应就是加索引,然后explain看了一下走什么索引了,结果很尴尬,三个表,只走了一个索引...一群人在那纠结为毛走不了索引. 无意间发 ...
- SynchronizedMap和ConcurrentHashMap的深入分析
http://blog.sina.com.cn/s/blog_5157093c0100hm3y.html java5中新增了ConcurrentMap接口和它的一个实现类ConcurrentHashM ...
- Python小代码_6_列表推导式求 100 以内的所有素数
import math a = [p for p in range(2, 100) if 0 not in [p % d for d in range(2, int(math.sqrt(p)) + 1 ...
- 628. Maximum Product of Three Numbers
Given an integer array, find three numbers whose product is maximum and output the maximum product. ...
- Eclipse创建Maven工程
Eclipse创建Maven工程: Eclipse: New -> Other -> Maven Project -> Next -> webapp -> Finish ...
- XML相关知识
XML的定义: XML即可扩展标记语言标记是指计算机所能理解的信息符号,通过此种标记,计算机之间可以处理包含各种信息的文章等.如何定义这些标记,既可以选择国际通用的标记语言,比如HTML,也可以使用 ...
- Oracle中的4大空值处理函数用法举例
nvl(exp1,exp2): 如果exp1为空,则返回exp2:否则返回exp1nvl2(exp1,exp2,exp3): ...