簡介
最近項目接觸到Openwrt的編譯和使用谁帕,op本身是一個定制的linux系統(tǒng)澜躺,兼容的包和語言也有很多,隨著物聯(lián)網(wǎng)的發(fā)展破婆,相信在路由器方面的應用會越來越多,luci作為一個已經(jīng)在openwrt上集成的web管理工具有很強大的功能胸囱,但我的項目里面需要修改和使用自己的配置文件祷舀,因此整理一下lua+uci的使用。
lua使用uci
- openwrt-lua-uci官方介紹->地址
- lua+uci使用筆記
uci格式的配置文件在/etc/config/目錄下
基本格式:
config interface 'wan'
option ifname 'eth0.2'
...
require("uci")
local x = uci.cursor()
local wanvalue = x:get("network","wan","ifname")
--value為eth0.2
```
````lua
require("uci")
local x = uci.cursor()
x:set("network", "wan", "ifname", "value")
x:commit("network")
```
如果config 沒有name旺矾,需要進行循環(huán)
3. 使用lua+linux命令
>os.execute()
示例:
os.execute("cat /proc/uptime")
注意execute成功會返回0蔑鹦,在命令行中輸入會顯示結果夺克,但
local res = os.execute("cat /proc/uptime") --注意res=0
如果需要在lua中獲取output值箕宙,使用io.popen()方法
示例:
```lua
local uptime=assert (io.popen("cat /proc/uptime"))
for line in uptime:lines() do
print(line)
end
uptime:close()
```