我正在尝试使用 CRON 运行 rails 工作。我找到的所有示例都将我引导到其他 rails 工具、插件、gem 等,这很好,但我真的只想使用 CRON,无论如何。我可以通过以下方式正常运行我的工作,但是当我尝试 cron 时,我没有任何运气(只是似乎没有做任何事情)。我想每 3 分钟运行一次(用于测试)。
/usr/bin/env ruby ~/Dropbox/98_2011/webs/apps238/swapper/script/runner /home/durrantm/Dropbox/98_2011/webs/apps238/swapper/app/controllers/scheduled_emails_controller.rb
我在 Linux Ubuntu 上。
我的路径有:
/var/lib/gems/1.8/bin:/home/durrantm/.rvm/gems/ruby-1.8.7-p302/bin:/home/durrantm/.rvm/gems/ruby-1.8.7-p302@global/bin:/home/durrantm/.rvm/rubies/ruby-1.8.7-p302/bin:/home/durrantm/.rvm/bin:/home/durrantm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/pgsql/bin
最佳答案
Cron 作业不会加载用户的环境。尝试在 crontab 或您需要的任何环境中的命令之前添加 RAILS_ENV=production。
例子:
RAILS_ENV=production
*/3 * * * * /your/command/here
或者,如果您想确保您拥有用户的完整环境,请在登录 shell 中执行命令:
*/3 * * * * bash --login -c '/your/command/here'
关于ruby-on-rails - Cron 作业无法运行,crontab 使用什么语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5849090/