I am running a Ruby app and every minute a script needs to run so that it sends emails out to various users.
The script works when I run it manually, however when running through cron it fails with the error "Rake: command not found".
I'm pretty new to all of this stuff and I know it will be something pretty basic but I can't find anything online that relates - there are some that are close but don't quite fit.
This is my script:
# USAGE - runs rake script on redmine@mycompany for email issue reply facility in redmine
rake -f Rakefile redmine:email:receive_imap RAILS_ENV="production"host=imap.gmail.com port=993 ssl=1 email@example.com password=<my_password> --trace
Date: Fri, 21 Aug 2015 08:23:01 GMT
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)
Subject: Cron <ec2-user@ip-172-xx-xx-xxx> sh /usr/local/bin/redmine-email.sh
Content-Type: text/plain; charset=UTF-8
/usr/local/bin/redmine-email.sh: line 5: rake: command not found
*/1 * * * * sh /usr/local/bin/redmine-email.sh
The issue here was that cron didn't have the PATH information. Added this and the job runs without an issue. The following information was entered into crontab and 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'
Thanks for your help everyone, apologies if my terminology is no good but I am still learning.