incrontab不执行命令

incrontab不执行命令

当我开箱即用地使用 incrontab 时,我的意思是没有任何更改,我没有得到任何结果,就好像命令没有执行一样。

我的 incron 行是: /crrae IN_CREATE,IN_CLOSE_WRITE,IN_MOVED_TO /usr/bin/unix2dos $#

日志提供的信息好像一切正​​常,但实际上没有

生成的 strace 是:incrontab_trace_0.txt

 0.000000 poll([{fd=4, events=POLLIN}, {fd=6, events=POLLIN}, {fd=8, events=POLLIN}], 3, -1) = 1 ([{fd=8, revents=POLLIN}])
17.616276 read(8, "\1\0\0\0\0\1\0\0\0\0\0\0000\0\0\0ExportSageJDE_CO"..., 32768) = 64
 0.000145 stat64("/crrae", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
 0.000147 time(NULL)                = 1399228077
 0.000056 stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=156, ...}) = 0
 0.000089 stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=156, ...}) = 0
 0.000082 stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=156, ...}) = 0
 0.000096 send(3, "<78>May  4 18:27:57 incrond[3183"..., 108, MSG_NOSIGNAL) = 108
 0.000104 clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7f60718) = 31838
 0.000816 poll([{fd=4, events=POLLIN}, {fd=6, events=POLLIN}, {fd=8, events=POLLIN}], 3, -1) = -1 EINTR (Interrupted system call)
 0.000834 --- SIGCHLD (Child exited) @ 0 (0) ---
 0.000033 read(4, 0x8069c40, 32)    = -1 EAGAIN (Resource temporarily unavailable)
 0.000057 write(5, "X", 1)          = 1
 0.000056 sigreturn()               = ? (mask now [])
 0.000072 poll([{fd=4, events=POLLIN}, {fd=6, events=POLLIN}, {fd=8, events=POLLIN}], 3, -1) = 1 ([{fd=4, revents=POLLIN}])
 0.000068 read(4, "X", 1)           = 1
 0.000054 read(4, 0xbfd22dd9, 1)    = -1 EAGAIN (Resource temporarily unavailable)
 0.000057 waitpid(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 1}], WNOHANG) = 31838
 0.000060 waitpid(-1, 0xbfd22dd4, WNOHANG) = -1 ECHILD (No child processes)
 0.000051 poll([{fd=4, events=POLLIN}, {fd=6, events=POLLIN}, {fd=8, events=POLLIN}], 3, -1) = 1 ([{fd=8, revents=POLLIN}])
 0.009198 read(8, "\1\0\0\0\10\0\0\0\0\0\0\0000\0\0\0ExportSageJDE_CO"..., 32768) = 64
 0.000074 stat64("/crrae", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
 0.000118 time(NULL)                = 1399228077
 0.000057 stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=156, ...}) = 0
 0.000084 stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=156, ...}) = 0
 0.000082 stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=156, ...}) = 0
 0.000090 send(3, "<78>May  4 18:27:57 incrond[3183"..., 108, MSG_NOSIGNAL) = 108
 0.000065 clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7f60718) = 31839
 0.000614 poll([{fd=4, events=POLLIN}, {fd=6, events=POLLIN}, {fd=8, events=POLLIN}], 3, -1) = -1 EINTR (Interrupted system call)
 0.000832 --- SIGCHLD (Child exited) @ 0 (0) ---
 0.000026 read(4, 0x8069c40, 32)    = -1 EAGAIN (Resource temporarily unavailable)
 0.000055 write(5, "X", 1)          = 1
 0.000054 sigreturn()               = ? (mask now [])
 0.000071 poll([{fd=4, events=POLLIN}, {fd=6, events=POLLIN}, {fd=8, events=POLLIN}], 3, -1) = 1 ([{fd=4, revents=POLLIN}])
 0.000067 read(4, "X", 1)           = 1
 0.000053 read(4, 0xbfd22dd9, 1)    = -1 EAGAIN (Resource temporarily unavailable)
 0.000051 waitpid(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 1}], WNOHANG) = 31839
 0.000058 waitpid(-1, 0xbfd22dd4, WNOHANG) = -1 ECHILD (No child processes)
 0.000050 poll([{fd=4, events=POLLIN}, {fd=6, events=POLLIN}, {fd=8, events=POLLIN}], 3, -1 <unfinished ...>

当我将 incron 更改为:

/crrae IN_CREATE,IN_CLOSE_WRITE,IN_MOVED_TO /usr/bin/unix2dos /crrae/$# 

或者

/crrae IN_CREATE,IN_CLOSE_WRITE,IN_MOVED_TO /usr/bin/unix2dos $@/$#

日志给了我这个:

May  4 18:15:10 srvovs incrond[20859]: (root) CMD (/usr/bin/unix2dos /crrae/u2dtmpPbqoFd)
May  4 18:15:10 srvovs incrond[20859]: (root) CMD (/usr/bin/unix2dos /crrae/u2dtmpN2Odxf)
May  4 18:15:10 srvovs incrond[20859]: (root) CMD (/usr/bin/unix2dos /crrae/u2dtmpN2Odxf)

多次修改,incron.conf均未修改。有任何想法吗?

答案1

unix2dos运行基于事件写入和关闭文件的命令 ( )CLOSE_WRITE就是所谓的“循环”。 incrontab具有内置的循环保护功能。

答案2

也许您应该尝试捕获 incron 正在做什么、何时以及为何进行操作。

#!/bin/bash

echo "[$( date )] $*" >>/tmp/myincronlog

并将 $% 添加到 incrontab 参数中。

鉴于您只为命令提供一个参数,这意味着它正在就地修改文件。这意味着 incron 操作将创建 incron 事件。虽然 incrond 会尝试处理此类实例,但前提是您用 IN_NO_LOOP 告诉它。但最好避免在 incron 操作中不修改目标文件而引发的问题,这是一种会触发 incron 的方法。

相关内容