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

时间:2015-08-21 08:27:29

标签: ruby cron rake crontab

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

1 个答案:

答案 0 :(得分:2)

这里的问题是cron没有PATH信息。添加了这个并且作业运行没有问题。以下信息已输入crontab和voila。

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'

感谢大家的帮助,如果我的术语不好而且我还在学习,请道歉。

相关问题