Luci.sys.exec() function shows syntax error when adding a variable

1k Views Asked by At

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.

0

There are 0 best solutions below