1

I'm trying to print IP address of a particular interface using luci.sys.exec() function. My requirement is to add a variable which consists of the interface name for eg: eth0 or eth1.

code executed is :

local interfacename= "eth0"
currentInterfaceIpAdd = luci.util.trim(luci.sys.exec("ifconfig " ..interfacename.." | grep 'inet' | awk '{gsub("addr:","",$2);  print $2 }'"))

Error is also observed because of the double quotes in gsub("addr:","",$2). But single quotes gives nill value. The same command with static interface name works fine in command line.

Amritha
  • 11
  • 1
  • don't you think it would make sense to provide the actual error message? – Piglet Jul 18 '17 at 09:38
  • /usr/lib/lua/luci/dispatcher.lua:206: Failed to execute template dispatcher target for entry '/admin/view/status'. The called action terminated with an exception: /usr/lib/lua/luci/template.lua:11: Failed to load template 'view/status'. Error while parsing template '/usr/lib/lua/luci/view/view/status.htm'. A syntax error occured near 'ceIpAdd = luci.util.trim(luci.sys.exec("ifconfig" ..interfaceName.." | grep 'inet' | awk '{gsub("addr:","",$2); print $2 }'")) – Amritha Jul 18 '17 at 09:50
  • 2
    If you need nested double quotes: `lua_string = "awk '{gsub(\"addr:\",\"\",$2);" ` – Egor Skriptunoff Jul 18 '17 at 15:31

0 Answers0