#!/usr/bin/lua function file_exists(name) local f=io.open(name,"r") if f~=nil then io.close(f) return true else return false end end function watch_mac(mac) command = "batctl n | grep -i " .. mac .. " | tr -s ' ' | cut -d' ' -f4" local handle = io.popen(command) local result = handle:read("*a") handle:close() return result:match("(.-)%s*$") end counterfile = "/var/run/alarmcounter" lastseen = watch_mac("a2:1b:3a:0b:3e:72") age_seconds = tonumber(lastseen:sub(1, -2)) or 1000 if age_seconds > 30 then if not file_exists(counterfile) then file = io.open(counterfile, "w") file:write("1") file:close() command = "ssh alarmuser@srv01.ffpi ./alarmmail.sh" local handle = io.popen(command) local result = handle:read("*a") handle:close() end else if file_exists(counterfile) then os.remove(counterfile) end end