2015-08-21 56 views
0

我正在運行Ruby應用程序,腳本需要每分鐘運行一次,以便將電子郵件發送給各個用戶。Rake:運行cron作業時未找到命令

當我手動運行腳本時,該腳本正常工作,但是當通過cron運行時,腳本會失敗,並顯示錯誤「Rake:command not found」。

我對所有這些東西都很陌生,我知道它會是一些非常基本的東西,但是我找不到任何涉及到的東西 - 有一些東西很接近但不太合適。

這是我的腳本:

#!/bin/bash 
# USAGE - runs rake script on [email protected] 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 [email protected] password=<my_password> --trace 
folder=Inbox 
allow_override=true 

和運行作業時從郵件輸出:

Date: Fri, 21 Aug 2015 08:23:01 GMT 
Message-Id: <[email protected]> 
X-Authentication-Warning: ip-172-xx-xx-xxx: ec2-user set sender to root using -f 
From: [email protected] (Cron Daemon) 
To: [email protected] 
Subject: Cron <[email protected]> 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作業,完全沒有問題。希望有任何幫助,謝謝。

+0

您是否嘗試以'bundle exec rake ...'的形式運行該命令...' – tekina

+0

剛剛嘗試過 - 仍然收到bundle:command not found – shaneoh

+0

如果您使用'rvm'或其他ruby版本管理器,您將不得不使用適當的ruby版本,否則它會採用默認的ruby版本。 –

回答

1

這裏的問題是,cron沒有PATH信息。添加了這個,作業運行沒有問題。以下信息被輸入到crontab和瞧。

PATH="/home/ec2-user/.rvm/gems/ruby-1.9.3-p551/bin:/home/ec2-user/.rvm/gems/[email protected]/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/[email protected]/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/[email protected]' 
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' 

感謝您的幫助大家,道歉,如果我的術語不好,但我仍然在學習。