bash - lua os.execute doesn't work if the script runs from /etc/rc.local -
i have simple lua script listens particular event , fire post request twilio.com web service start call , send mail.
#!/usr/bin/lua -- february 2015, suxsem local sock = require("socket") local mosq = require("mosquitto") local mqtt = mosq.new("sonny_lua_scattato", true) mqtt:login_set("***", "***") local call = function (from, to) os.execute([[curl -x post 'https://api.twilio.com/2010-04-01/accounts/***/calls.json' \ --data-urlencode 'to=]] .. .. [[' \ --data-urlencode 'from=]] .. .. [[' \ -d 'url=https://demo.twilio.com/welcome/voice/' \ -d 'method=get' \ -d 'fallbackmethod=get' \ -d 'statuscallbackmethod=get' \ -d 'timeout=20' \ -d 'record=false' \ -u ***:***> twiliolog.txt]]) end local callback = function (mid, topic, message) print("received: " .. topic .. ": " .. message) if topic == "arsenialarm/scattato" local call_from = "+393317893***" local call_to = {"+393299573***", "+393473621***", "+393492829***"} i, in ipairs(call_to) call(call_from, to) end local rcpt = {"semer***.stef***@hotmail.it", "miky.semer***@live.it"} local sbj = "antifurto arseni" local bdy = "antifurto arseni - " .. os.date("%t - %d/%m/%y") os.execute('echo -e "to: ' .. table.concat(rcpt, ",") .. '\r\nsubject: ' .. sbj .. '\r\n\r\n' .. bdy .. '" | msmtp --from=default -t') end end mqtt:callback_set("on_message", callback) local connected = false mqtt:callback_set("on_connect", function () print("connected") connected = true mqtt:subscribe("arsenialarm/scattato", 2) end) mqtt:callback_set("on_disconnect", function () print("disconnected") connected = false end) mqtt:connect("127.0.0.1", 1883, 60) while true mqtt:loop() if connected sock.sleep(1.0) -- seconds else sock.sleep(5.0) mqtt:reconnect() end end
now... run script following command:
cd /root/mqtt_client/ ; lua /root/mqtt_client/mqtt_scattato.lua &
everything works good, receive tha call , mail , in twiliolog.txt (if @ code "curl ... > twiliolog.txt" start call) can see twilio response.
but
if put same command (cd /root/mqtt_client/ ; lua /root/mqtt_client/mqtt_scattato.lua &) inside /etc/rc.local strange happens: 1) receive mail not call! 2) twiliolog.txt (output of curl) correctly created it's empty!
my platform router openwrt barrier breaker.
i hope can me, thanks!
i ended removing os.execute call entirely. i'm using lua native https sockets:
local https = require("ssl.https") local call = function (from, to) local body = "to=" .. .. "&from=" .. .. "&url=https://demo.twilio.com/welcome/voice/&timeout=20&record=false" https.request { protocol = "tlsv1", method="post", url="https://api.twilio.com/2010-04-01/accounts/***/calls.json", source=ltn12.source.string(body), headers = {["content-length"] = #body, ["content-type"] = "application/x-www-form-urlencoded"}, user="***", password="***", } end
i'm still using os.execute send mail , works fine, think problem related combination of curl + os.execute + start script on boot.
i have still no clue problem cause behaviour
Comments
Post a Comment