openwrt lua demo

cjson = require("cjson")
local param_nil = ''
local paramstr = nil;
local param = {}
local retdata = nil;

-- echo -e "\033[30m黑色字\033[0m"  
-- echo -e "\033[31m红色字\033[0m"  
-- echo -e "\033[32m绿色字\033[0m"  
-- echo -e "\033[33m黄色字\033[0m"  
-- echo -e "\033[34m蓝色字\033[0m"  
-- echo -e "\033[35m紫色字\033[0m"  
-- echo -e "\033[36m天蓝字\033[0m"  
-- echo -e "\033[37m白色字\033[0m"  
function print_red(data)
	data = string.gsub(data,"[\r\n]",'')
	local outdata = string.format('echo -e \'\\033[0;31m \'%s\' \\033[0m\'',data);
	os.execute(outdata);
end

function print_green(data)
	data = string.gsub(data,"[\r\n]",'')
	local outdata = string.format('echo -e \'\\033[0;32m \'%s\' \\033[0m\'',data);
	os.execute(outdata);
end

function print_blue(data)
	data = string.gsub(data,"[\r\n]",'')
	local outdata = string.format('echo -e \'\\033[0;36m \'%s\' \\033[0m\'',data);
	os.execute(outdata);
end

function exec_cmd(cmdstr,paramstr)

	print('')
	local clistr = string.format("%s %s",cmdstr,paramstr)
	print_green(clistr)
	local cli = io.popen(clistr)
	local data = cli:read("*all")

	return data
end

你可能感兴趣的:(shell)