Skip to content

Instantly share code, notes, and snippets.

@hamishforbes
Last active September 6, 2016 11:08
Show Gist options
  • Save hamishforbes/ccb3106fe9a381cb59904fe02bc3b617 to your computer and use it in GitHub Desktop.
Save hamishforbes/ccb3106fe9a381cb59904fe02bc3b617 to your computer and use it in GitHub Desktop.
settings {
logfile = "/var/log/lsyncd/lsyncd.log",
maxProcesses = 20,
pidfile = "/var/run/lsyncd.pid",
statusFile = "/tmp/lsyncd.status",
--nodaemon = true
}
local function clamScan(event, path)
local host = event.config.host
local port = event.config.port
-- Build command: echo "SCAN <filepath>" | nc <host <port>
local cmd = {
[[echo "SCAN ]],
path,
[[" | nc ]],
host,
" ",
port
}
cmd = table.concat(cmd, "")
log("Normal", cmd)
spawnShell(event, cmd)
return
end
local function clamHandler(event)
if event.isdir then
-- ignores events on dirs
return
end
local path = event.source .. event.pathname
return clamScan(event, path)
end
clamscan = {
-- Enable the extra config options
checkgauge = {
["host"] = true,
["port"] = true,
["exclude"] = true,
["on_start"] = true,
},
delay = 0,
maxProcesses = 20,
-- Default host/port
host = "127.0.0.1",
port = 3310,
onCreate = clamHandler,
onModify = clamHandler,
onStartup = function(event)
-- TODO: apply excludes here
if event.config.on_start ~= false then
log("Normal", "Scanning target dir: "..event.source)
clamScan(event, event.source)
end
end
}
sync {
clamscan,
--on_start = false,
source = '/tmp/clamtest/',
exclude = 'tmp/'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment