summaryrefslogtreecommitdiff
path: root/noprml/noprml.lua
blob: 72267ae737723f0572196fb4cce913745a5b4e05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/lua
--
-- send now and next cart# and length to nopsyncd
--  this script should be called by the now/next macro cart
--  the arguments should be:  now# nowlen next# nextlen
--

local queue_name = "/rhnop"

mq = require "luamq"

-- reading timestamp (milliseconds since epoch)
local p = assert(io.popen("/bin/date --utc '+%s %N'" , 'r'))
local time = assert(p:read('*l'))
p:close()
local s, ns = assert(string.match(time, "([0-9]+) ([0-9]+)"))
local timestamp = s*1000 + math.floor(ns/1000000)

-- check arguments
if #arg < 4 then
   io.stderr:write("too few parameters\n")
   os.exit(1)
end

-- open message queue
local q, err = mq.create(queue_name, "wo")
if q == nil then
   io.stderr:write("creation of message queue failed: " .. err .. "\n")
   os.exit(1)
end

-- send out message to nopsyncd
local result, err = mq.send(q, timestamp .. " " .. arg[1] .. " " .. arg[2] .. " " .. arg[3] .. " " .. arg[4], 0)
if result == nil then
   io.stderr:write("sending message failed: " .. err .. "\n")
   os.exit(2)
end

mq.close(q)