简体   繁体   English

通过 Crontab 作业运行 `wsgetmail` 服务 CentOS 6

[英]Running `wsgetmail` service via Crontab job CentOS 6

I want to run the below via Crontab job and not working but when put them in sh file and run the sh manually it works fine.我想通过 Crontab 作业运行以下命令但无法正常工作,但是当将它们放入sh文件并手动运行sh时,它工作正常。

Sh file path: /opt/etc/rt4/test.sh and the content as below: sh文件路径: /opt/etc/rt4/test.sh内容如下:

wsgetmail --config=account01.json wsgetmail --config=account02.json wsgetmail --config=account01.json wsgetmail --config=account02.json

Running manually: sh /opt/etc/rt4/test.sh it works fine.手动运行: sh /opt/etc/rt4/test.sh它工作正常。

Crontab: */1 * * * * /opt/etc/rt4/test.sh crontab: */1 * * * * /opt/etc/rt4/test.sh

Crontab runs this file but those commands are not working. Crontab 运行此文件,但这些命令不起作用。

I have other Crontab jobs and they are working fine as intended.我还有其他 Crontab 工作,它们按预期工作正常。

Running manually: sh /opt/etc/rt4/test.sh it works fine.手动运行:sh /opt/etc/rt4/test.sh 它工作正常。

Crontab: */1 * * * * /opt/etc/rt4/test.sh crontab: */1 * * * * /opt/etc/rt4/test.sh

Those are not the same thing, as 1st line shebang, and chmod a+x test.sh , will affect the behavior.这些不是一回事,因为第一行 shebang 和chmod a+x test.sh会影响行为。 Either remove "sh" when running manually, or prepend it to the cron command.手动运行时删除“sh”,或者将其添加到 cron 命令之前。


Run $ id , and determine if that's different from how the cron command runs, perhaps by having cron log id output.运行$ id ,并确定这是否与 cron 命令的运行方式不同,也许是通过 cron 日志id输出。 Running as yourself manually, versus as root (uid=0) under cron, can change the behavior of that command.以你自己的身份手动运行,而不是以 root (uid=0) 身份在 cron 下运行,可以更改该命令的行为。

Numerous other things are different under cron, such as lack of a pty. cron 下的许多其他事情都不同,例如缺少 pty。


Take a look at $ env | sort看看$ env | sort $ env | sort manually.手动$ env | sort Then run it under crond , and note the huge difference.然后在crond下运行它,并注意巨大的差异。

Pay special attention to PATH.特别注意路径。 It is likely to be much shorter under cron, and that can lead to "command not found" diagnostics.它在 cron 下可能会更短,这可能导致“未找到命令”诊断。 But you chose not to share any diagnostic error messages with us, so coming up with a definitive diagnosis of this amounts to a mind reading exercise.但是您选择不与我们分享任何诊断错误消息,因此对此做出明确的诊断相当于读心术。

The crontab and terminal are two different environments, the wsgetmail perl module command is recognizable for terminal but to make it recognizable for corntab we have to add the full path to the module (wsgetmail) in the shell script. crontab 和终端是两个不同的环境,wsgetmail perl 模块命令对于终端是可识别的,但要使其能够被 corntab 识别,我们必须在 shell 脚本中添加模块 (wsgetmail) 的完整路径。 in this case test.sh should looks like this:在这种情况下 test.sh 应该是这样的:

#!/bin/bash
/usr/local/bin/wsgetmail --config=account01.json 
/usr/local/bin/wsgetmail --config=account02.json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM