Lsyncd选项问题

我正在尝试使用名为 lsyncd 的软件,它使用一个用 Lua 编写的配置文件来存储配置选项。

settings = {
logfile = "/logs/log.log",
pidfile = "/var/run/lsyncd.pid",
statusFile="/var/log/lsyncd.stat",
statusIntervall=5,
delay = 1
}
sync {
default.rsync,
source = "/source/folder",
target = "/destination/folder",
excludeFrom="/etc/exclude",
}

手册讲述了在动作上运行命令的能力,甚至给出了一个例子

fgroup = "staff"

-----
-- script for all changes.
--
command =
-- checks if the group is the one enforced and sets them if not
'[[
perm=`stat -c %A ^sourcePathname`
if test `stat -c %G ^sourcePathname` != ]]..fgroup..'[[; then
        /bin/chgrp ]]..fgroup..'[[ ^sourcePathname || /bin/true;
fi
]] ..

-- checks if the group permissions are rw and sets them
'[[
if test `expr match $perm "....rw"` = 0; then
        /bin/chmod g+rw ^sourcePathname || /bin/true;
fi
]] ..

-- and forces the executable bit for directories.
'[[
if test -d ^sourcePathname; then
        if test `expr match $perm "......x"` -eq 0; then
                /bin/chmod g+x ^^sourcePathname || /bin/true;
        fi
fi
]]

-- on startup recursively sets all group ownerships
-- all group permissions are set to 'rw'
-- and to executable flag for directories
--
-- the hash in the first line is important, otherwise due to the starting
-- slash, Lsyncd would think it is a call to the binary /bin/chgrp only
-- and would optimize the shell call away.
--
startup =
'[[#
/bin/chgrp -R ]]..fgroup..'[[ ^source || /bin/true &&
/bin/chmod -R g+rw ^source || /bin/true &&
/usr/bin/find ^source -type d | xargs chmod g+x
]]

     gforce = {
        maxProcesses = 99,
        delay        = 1,
        onStartup    = startup,
        onAttrib     = command,
        onCreate     = command,
        onModify     = command,
        -- does nothing on moves, they won't change permissions
        onMove       = true,
   }

   sync{gforce, source="/path/to/share"}

但我只想在 onCreate、onModify、onMove 上执行一个简单的本地命令

/path/to/script.sh args

我知道这可能很简单,但我无法弄清楚。

点赞
用户664216
用户664216

命令似乎是字符串。所以我会尝试:

...
onStartup = "/path/to/script.sh args",
onAttrib  = [[/path/to/script.sh args]],  -- '',""和[[ ]]都是字符串定界符
....
2012-06-01 08:38:58
用户2538262
用户2538262

请尝试使用 python 脚本软件 Watcher,并将 jobs.yml 配置为示例。

......
事件:['create''modify''move']
......
命令:/path/to/script.sh args
2013-07-02 10:02:23
用户693291
用户693291

尝试像这样做:

my_cmds =
[[
    /path/to/script.sh args
]]

monitor =
{
    delay    = 1,
    onAttrib = my_cmds,
    onCreate = my_cmds,
    onModify = my_cmds,
    onMove   = my_cmds,
}

sync
{
    monitor,
    source = "/source/folder",
    target = "/destination/folder",
}

(翻译完毕)

2014-08-06 17:46:51