bash 在 CentOS 6.4 下 incrond 运行但不执行命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18238962/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 06:15:14  来源:igfitidea点击:

incrond running but not executing command under CentOS 6.4

bashinotifycentos6selinux

提问by JawzX

I have installed incron from the EPEL repository (before you ask; YES, I also tried downloading the source and compiling locally; same results) and am attempting to set up a process on my CentOS 6.4 (final) virtual box that I have successfully prototyped on my local Ubunto 12.04 machine:

我已经从 EPEL 存储库安装了 incron(在你问之前;是的,我也尝试下载源代码并在本地编译;相同的结果)并试图在我已经成功原型化的 CentOS 6.4(最终)虚拟机上设置一个进程在我本地的 Ubunto 12.04 机器上:

Some information up front:

前面的一些信息:

  • SELinux is set PERMISSIVE
  • I have added my script(s) and called executables to all with NOPASSWD using visudoto get around some permissions issues...
  • SELinux 设置为 PERMISSIVE
  • 我已经使用 NOPASSWD 添加了我的脚本并调用了所有可执行文件来visudo解决一些权限问题......

If I invoke my script from the command line with sudo /path/to/my/script.sh argumentsit works like a charm.

如果我从命令行调用我的脚本,sudo /path/to/my/script.sh arguments它就像一个魅力。

sudo service incrond statusverifies that incrond is running. root and myusername are added to /etc/incron.allow, /etc/incron.denyis empty.

sudo service incrond status验证 incrond 正在运行。root 和 myusername 添加到/etc/incron.allow/etc/incron.deny为空。

My incrotab for root is:

我的根 incrotab 是:

/path/to/dropfolder/ IN_CLOSE_WRITE sudo /path/to/my/script.sh $@/$#

Events in /path/to/dropfolder/result in exactly NOTHING happening. No logs are generated, no messages, no actions occur on the files in the folder.

事件/path/to/dropfolder/导致完全没有发生。不生成日志,不生成消息,也不会对文件夹中的文件执行任何操作。

So I have researched: it was suggested that cronruns in a minimal environment and that to execute complex commands/scripts you may have to execute your .bashrcand/or export your PATH at the beginning of the cron command.

所以我进行了研究:建议cron在最小环境中运行,并且要执行复杂的命令/脚本,您可能必须.bashrc在 cron 命令的开头执行和/或导出 PATH。

Note:I can find no documentation supporting that incronalso runs in a minimal environment, but as my google-fu (and bing-fu!) failed to result in any helpful results related directly to incronI figured WTH, I'll try that!

注意:我找不到任何支持incron在最小环境中运行的文档,但是由于我的 google-fu(和 bing-fu!)未能产生与incron我认为 WTH直接相关的任何有用结果,我会尝试!

Edit:Documentation indicates that incronrun from system tables or root takes env from its host enviroment, therefore only incronexecuted by non-root users should require any sort of env or PATH fiddling

编辑:文档表明incron从系统表或 root 运行从其主机环境中获取 env,因此仅incron由非 root 用户执行应该需要任何类型的 env 或 PATH 摆弄

So… incrontab for root:

所以...... root的incrontab:

/path/to/dropfolder IN_CLOSE_WRITE . /home/myusername/.bashrc; export PATH=$PATH:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin; sudo /path/to/my/script.sh $@/$#"

No dice… tried &&instead of ;= no dice. If you can think of a variation on the above I've probably tried it…

没有骰子......尝试&&而不是;=没有骰子。如果您能想到上述的变体,我可能已经尝试过……

So, lets try a little restorecond -R /usr/sbin/incrond /etc/incron*action! Huh, no change there either. service incrond stopfollowed by service incrond startand then service incrond restart… nope, nope, and nope.

所以,让我们尝试一个小动作restorecond -R /usr/sbin/incrond /etc/incron*!呵呵,那里也没有变化。 service incrond stop其次service incrond start,然后service incrond restart......没了,没了,和没了。

Drastic measures: yum remove incronand yum install incron, chkconfig incrond onand then for good measure a sudo reboot!

激烈的措施:yum remove incronyum install incronchkconfig incrond on然后是好的措施 a sudo reboot

Nothing.

没有。

I don't even get anything from /tmp/ IN_ALL_EVENTS echo boo>>/home/myusername/boofile.txt, hence my inability to even do an env>>envfile.txtto check whether incronis running in a sparse environment… (see above note)

我什至没有从 中得到任何东西/tmp/ IN_ALL_EVENTS echo boo>>/home/myusername/boofile.txt,因此我什env>>envfile.txt至无法检查是否incron在稀疏环境中运行......(见上面的注释)

And yet: service incrond statusyields incrond (pid xxxx) is running...

然而:service incrond status产量incrond (pid xxxx) is running...

What am I missing? It has to be big and obvious and I hope someone can make me feel like an idiot in short order!

我错过了什么?它必须大而明显,我希望有人可以在短时间内让我觉得自己像个白痴!

further examination of /var/log/cronyields results like this: Aug 14 15:05:30 hostname incrond[1584]: (root) CMD (sudo /path/to/DropFolder/script/subfolder/script-Beta-1.sh /home/username/DropFolder/testfile.file)-yes I made sure my script was executable..

进一步检查/var/log/cron产生这样的结果:-是的,Aug 14 15:05:30 hostname incrond[1584]: (root) CMD (sudo /path/to/DropFolder/script/subfolder/script-Beta-1.sh /home/username/DropFolder/testfile.file)我确保我的脚本是可执行的..

so incrond is indeed attempting to do SOMETHING, but I get no output anywhere... even a simple echo > /dev/pts/0produces nada results.

所以 incrond 确实试图做一些事情,但我在任何地方都没有输出......即使是简单的也会echo > /dev/pts/0产生 nada 结果。

  • thanks for fixing my crap formatting job
  • 感谢您修复我的垃圾格式化工作

回答by JawzX

Ok, here's the answer:

好的,这是答案:

Despite all documentation I can find declaring it to be the contrary, incrondunder CentOS 6.4 runs in a sparse environment and behaves as cron. this is NOT the case under Ubuntu, where incron inherits its environment from root for system tables and root tables and only user tables run in a sparse environment. This of course means that if you're calling a script (I am) the script needs to build it's environment and every thing must have a full path. EVERYTHING. (well, except for shell builtins :p)

尽管我发现所有文档都声明它是相反的,但incrond在 CentOS 6.4 下在稀疏环境中运行并表现为cron. 这不是在 Ubuntu 下的情况,其中 incron 从 root 继承其系统表和根表的环境,并且只有用户表在稀疏环境中运行。这当然意味着如果您正在调用脚本(我是),该脚本需要构建它的环境,并且每件事都必须有一个完整的路径。一切。(好吧,除了 shell 内置函数:p)

numerous Google and and Bing and Stack Overflow and Server Fault searches all told me that cronoperates this way, but they all also seemed to indicate that incronoperates as described in the documentation, which it DOES under Ubuntu...

许多 Google 和 Bing 以及 Stack Overflow 和 Server Fault 搜索都告诉我以cron这种方式运行,但它们似乎都表明incron按照文档中的描述运行,它在 Ubuntu 下执行...

Bottom line, it works now, yay!

最重要的是,它现在有效,是的!

  • I guess this just goes to show: when in doubt define the environment and use full paths... er, actually, just do that all time and save yourself a headache.
  • 我想这只是为了表明:当有疑问时定义环境并使用完整路径......呃,实际上,只要一直这样做,就可以避免头痛。

(this does not address my problem with applying a SELinux security policy for incron, but I'll worry about that later, in another post...)

(这并没有解决我为 应用 SELinux 安全策略的问题incron,但我稍后会在另一篇文章中担心这个问题......)