【发布时间】:2015-11-15 03:01:23
【问题描述】:
我正在运行一个 Ruby 应用程序,每分钟都需要运行一个脚本,以便将电子邮件发送给不同的用户。
当我手动运行该脚本时它可以工作,但是当通过 cron 运行时它会失败并显示错误“Rake: command not found”。
我对所有这些东西都很陌生,我知道这将是一些非常基本的东西,但我在网上找不到任何相关的东西 - 有些很接近但不太合适。
这是我的脚本:
#!/bin/bash
# USAGE - runs rake script on redmine@mycompany for email issue reply facility in redmine
cd /usr/local/src/redmine-3.0.3
rake -f Rakefile redmine:email:receive_imap RAILS_ENV="production"host=imap.gmail.com port=993 ssl=1 username=redmine@mydomain.com password=<my_password> --trace
folder=Inbox
allow_override=true
以及运行作业时邮件的输出:
Date: Fri, 21 Aug 2015 08:23:01 GMT
Message-Id: <201508210823.t7L8N1U6031959@ip-172-xx-xx-xxx>
X-Authentication-Warning: ip-172-xx-xx-xxx: ec2-user set sender to root using -f
From: root@ip-172-xx-xx-xxx (Cron Daemon)
To: ec2-user@ip-172-xx-xx-xxx
Subject: Cron <ec2-user@ip-172-xx-xx-xxx> sh /usr/local/bin/redmine-email.sh
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: <LANG=en_US.UTF-8>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/ec2-user>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=ec2-user>
X-Cron-Env: <USER=ec2-user>
/usr/local/bin/redmine-email.sh: line 5: rake: command not found
我的 crontab:
*/1 * * * * sh /usr/local/bin/redmine-email.sh
所以我不知道发生了什么 - 我在这台机器上运行其他 cron 作业,完全没有问题。非常感谢任何帮助,谢谢。
【问题讨论】:
-
你是否尝试以
bundle exec rake ...运行命令 -
刚刚尝试过 - 仍然得到 bundle: command not found
-
如果您使用
rvm或其他ruby 版本管理器,则必须使用适当的ruby 版本,否则它将采用默认的ruby 版本。 -
你安装了 bundler gem 吗?如果没有,请通过
gem install bundler安装它。在较新版本的 rvm 中,默认不添加。 -
我正在使用 rvm,但只安装了一个 ruby 版本(1.9.3),它适用于我们的应用程序。同样,脚本在手动运行时运行,而不是在由 cron 运行时运行。我还安装了捆绑程序(1.10.5)。