cron 中的 rake 任务
我有一个运行我的 rake 任务的 shell 脚本 (/home/user/send_report.sh
):
cd /home/user/rails/app
/home/user/.rvm/gems/ruby-1.9.2-p136/bin/rake report:send
当我在控制台中运行它时 sh /home/user/send_report.sh
它工作正常。
我试图用我的脚本创建一个 cron 任务:*/10 * * * * sh /home/user/send_report.sh
,但没有任何反应! Rake 任务应该发送邮件,但这并没有发生。
/var/log/cron.log
的内容:
Jun 2 21:40:01 ubuntu CRON[1253]: (user) CMD (sh /home/user/send_report.sh)
Jun 2 21:40:01 ubuntu CRON[1251]: (user) MAIL (mailed 240 bytes of output but got status 0x0001#012)
请帮助我使用 crontab 获取可工作的 rake 脚本。
I have a shell script (/home/user/send_report.sh
) that runs my rake task:
cd /home/user/rails/app
/home/user/.rvm/gems/ruby-1.9.2-p136/bin/rake report:send
When I run it in console sh /home/user/send_report.sh
it works properly.
I am trying to make a cron task with my script: */10 * * * * sh /home/user/send_report.sh
, but nothing happens! Rake task should send mail, but this does not happen.
Content of /var/log/cron.log
:
Jun 2 21:40:01 ubuntu CRON[1253]: (user) CMD (sh /home/user/send_report.sh)
Jun 2 21:40:01 ubuntu CRON[1251]: (user) MAIL (mailed 240 bytes of output but got status 0x0001#012)
Please, help me to get the working rake script with crontab.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除了您应该使用 /bin/sh 之外,我没有发现 cron 作业有任何问题。当您手动运行时,您会收到您所说的电子邮件,对吗?它不仅在您使用 cron 时才起作用?看来这可能是电子邮件服务器的配置错误或者可能是邮件服务器端口被阻止?
Apart from the fact that you should use /bin/sh, i don't see anything wrong on the cron job. When you run manually, you get the email as you said right ? It does not only work when you do it with cron ? It seems that it could be a misconfiguration of the email server or maybe that the mail server port is blocked ?
问题是 RVM 单用户安装不支持 cron 任务。安装 RVM 作为多用户并且 crontab 工作正常。
Problem was that RVM single-user installation doesn't supports cron tasks. Installed RVM as multi-user and crontab worked properly.