首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Lsyncd选项问题

Lsyncd选项问题
EN

Stack Overflow用户
提问于 2012-06-01 12:55:53
回答 3查看 2K关注 0票数 1

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

代码语言:javascript
复制
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",
}

该手册谈到了在操作时运行命令的能力,甚至还有一个示例

代码语言:javascript
复制
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

代码语言:javascript
复制
 /path/to/script.sh args

我知道这可能很简单,但我搞不懂。

EN

回答 3

Stack Overflow用户

发布于 2012-06-01 16:38:59

命令看起来像是字符串。然后我会试着:

代码语言:javascript
复制
...
onStartup = "/path/to/script.sh args",
onAttrib  = [[/path/to/script.sh args]],  -- both '', "", and [[ ]] are string delimiters
....
票数 0
EN

Stack Overflow用户

发布于 2014-08-07 01:46:52

尝试如下所示:

代码语言:javascript
复制
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",
}
票数 0
EN

Stack Overflow用户

发布于 2013-07-02 18:02:23

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

代码语言:javascript
复制
......
events: ['create', 'modify', 'move']
......
command:/path/to/script.sh args
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10844610

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档