OpenWrt中使用lua获取emmc挂载容量空间信息,记录一下。
#!/usr/local/bin/lua
print("lua test")
print("")
local emmc1 = {}
local emmc2 = {}
local f = io.popen("df -k 2>/dev/null")
if f then
for file in f:lines() do
--print(file)
local acl = string.find(file,'sda3')
--print(acl)
if acl then
print("df -k:")
print(file)
for v in string.gmatch(file, "%S+") do
emmc1[#emmc1 + 1] = v
end
emmc_dev, size, used, available, usep, mount_dir = file:match("(%S+) +(%S+) +(%S+) +(%S+) +(%S+) +(%S+)")
end
end
f:close()
end
print("emmc1:")
for i= 1, 6 do
print(emmc1[i])
end
print("emmc2:")
print(emmc_dev)
print(size)
print(used)
print(available)
print(usep)
print(mount_dir)
logread@logread:lua$ lua test.lua
lua test
df -k:
/dev/sda3 153764624 43609440 102274484 30% /home/logread/yubo.wang
emmc1:
/dev/sda3
153764624
43609440
102274484
30%
/home/logread/yubo.wang
emmc2:
/dev/sda3
153764624
43609440
102274484
30%
/home/logread/yubo.wang