Rake:运行 cron 作业时找不到命令

Rake: command not found when running cron job

我正在 运行 开发一个 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 作业完全没有问题。非常感谢任何帮助,谢谢。

这里的问题是 cron 没有 PATH 信息。添加了这个,作业运行没有问题。将以下信息输入到 crontab 中,瞧。

PATH="/home/ec2-user/.rvm/gems/ruby-1.9.3-p551/bin:/home/ec2-user/.rvm/gems/ruby-1.9.3-p551@global/bin:/home/ec2-user/.rvm/rubies/ruby-1.9.3-p551/bin:/home/ec2-user/.rvm/gems/ruby-1.9.3-p551/bin:/home/ec2-user/.rvm/gems/ruby-1.9.3-p551@global/bin:/home/ec2-user/.rvm/rubies/ruby-1.9.3-p551/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/.rvm/bin:/home/ec2-user/bin"
GEM_HOME='/home/ec2-user/.rvm/gems/ruby-1.9.3-p551'
GEM_PATH='/home/ec2-user/.rvm/gems/ruby-1.9.3-p551:/home/ec2-user/.rvm/gems/ruby-1.9.3-p551@global'
MY_RUBY_HOME='/home/ec2-user/.rvm/rubies/ruby-1.9.3-p551'
IRBRC='/home/ec2-user/.rvm/rubies/ruby-1.9.3-p551/.irbrc'
RUBY_VERSION='ruby-1.9.3-p551'

感谢大家的帮助,如果我的术语不好,请见谅,但我仍在学习中。