shaneoh shaneoh - 1 month ago 10
Ruby Question

Rake: command not found when running cron job

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
cd /usr/local/src/redmine-3.0.3
rake -f Rakefile redmine:email:receive_imap RAILS_ENV="production" port=993 ssl=1 password=<my_password> --trace

And the output from the mail when running the job:

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/
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/ line 5: rake: command not found

My crontab:

*/1 * * * * sh /usr/local/bin/

So I have no idea what is going on - I run other cron jobs on this machine with no issues at all. Would appreciate any help, thanks.


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.


Thanks for your help everyone, apologies if my terminology is no good but I am still learning.