#!/usr/bin/lua function neighbourcount() local handle = io.popen("batctl n | grep ibss0 | wc -l") local result = handle:read("*a") handle:close() return result end function ifstate() local file = io.open("/sys/class/net/client0/operstate", "r") local result = file:read("*l") file:close() return result end state = ifstate() if neighbourcount() == 0 then if state == "up" then os.execute("ip link set down dev client0") end else if state == "down" then os.execute("ip link set up dev client0") end end