Ubuntu 的 Cron 不触发 ruby 方法
crontab -l 给了我这个
0,2,4,6,8,10 * * * * /bin/bash -l -c 'cd /home/ruben/Monitoring ; script/rails runner Ping.check_pings'
为什么这不起作用? 如果我在命令行中尝试“cd /home/ruben/Monitoring ; script/rails runner Ping.check_pings”,它会起作用。我也用“&&”尝试过作为 ”;”
crontab -l gives me this
0,2,4,6,8,10 * * * * /bin/bash -l -c 'cd /home/ruben/Monitoring ; script/rails runner Ping.check_pings'
Why does this not work?
If i try "cd /home/ruben/Monitoring ; script/rails runner Ping.check_pings" in the command line it works. I have also tried it with "&&" as ";"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该问题可能与 PATH 或其他一些环境变量(如 GEM_HOME)有关,这些变量在命令行环境中正确定义,但在 cron 环境中则不然。
The problem may be related to PATH, or to some other environment variable (like GEM_HOME), that is defined properly in your command-line environment, but not in cron's environment.
crontab 不随用户环境运行,而是创建自己的精简环境。这包括非常小的 PATH - /usr/bin:/usr/sbin:。以及其他一些变量。在此处查看更多信息 - http://adminschoice.com/crontab-quick-reference
最简单的解决方案是添加 '。 ~/.profile' 在运行 Rails 之前,或以其他方式修复路径。
顺便说一句,在您尝试将 PATH=/my/path/here;$PATH 添加到 crontab 之前 - 该语法(变量扩展)也是不允许的
crontab doesn't run with the enviroment of the user, rather it creates it's own slimmed down enviroment. This includes very small PATH - /usr/bin:/usr/sbin:. and some other variables. See more here - http://adminschoice.com/crontab-quick-reference
Easiest solution is to add '. ~/.profile' before you run rails, or to fix path in some other way.
BTW, before you try to add PATH=/my/path/here;$PATH into crontab - that syntax (variable expansion) is not allowed either