1

I've read this post Whenever errors and tried to implement the recommendations to no avail. I'm still receiving '/bin/bash: bundle: command not found' error. On Amazon EC2.

which ruby

/usr/local/bin/ruby

which bundler

/usr/local/bin/bundler

schedule.rb

env :PATH, ENV['PATH']
require File.expand_path('../application', __FILE__)
set :output, "log/cron_log.log"

every 1.minutes do
  rake "calculate:calculate"
end

crontab -e

          • /bin/bash -l -c 'cd /srv/www/myapp/releases/20141022032959 && RAILS_ENV=development bundle exec rake calculate:calculate --silent >> log/cron_log.log 2>&1'

tail -f log/cron_log.log

/bin/bash: bundle: command not found

When I copy the command out of crontab and run it directly, everything works fine (cd /srv/www/myapp/releases/20141022032959 && RAILS_ENV=development bundle exec rake calculate:calculate --silent >> log/cron_log.log 2>&1). It's the prepending of /bin/bash that's messing this up.

How do I get schedule.rb / whenever gem to recognize correct PATH.

Community
  • 1
  • 1
Jacques Betancourt
  • 2,652
  • 3
  • 18
  • 19

3 Answers3

17

Forget about PATH settings in cron files. Setting the PATH does not work.

Set the path to bundle explicitly in your config/schedule.rb

set :bundle_command, "/usr/local/bin/bundle exec"

Edit: exec added so that task can run

Joe Czucha
  • 4,123
  • 2
  • 20
  • 28
vanboom
  • 1,274
  • 12
  • 20
  • 3
    just tested it. shouldn't that actually be ``"/usr/local/bin/bundle exec"``? – srecnig Sep 17 '15 at 06:24
  • 1
    Yes, the correct would be `"/usr/local/bin/bundle exec"` – Ivan Santos Oct 14 '15 at 15:04
  • 1
    The problem with this is that `schedule.rb` is generally versionned under git. From what we know, the path of `bundle` can change depending on machine. How do you handle it then? – lkartono Oct 20 '15 at 03:41
  • @El-Key did you got the solution on the path change depending on machine. its really interesting coz one machine might have different path and another one different. is there any correct way to do this? – VoidZero Jul 21 '16 at 19:15
  • 1
    @VoidZero I added this `env :PATH, ENV['PATH']` at the beginning of the file `schedule.rb` – lkartono Jul 22 '16 at 03:10
3

If none of the above solution works this did it for me without any additional setup

rvm cron setup

This will include all the right paths for gems so you do this on your machine and you are good to go.

Sedad Kosovac
  • 658
  • 5
  • 14
2

If using rbenv, the path is "/home/YOUR_USER/.rbenv/shims/bundle", so you shoud write at the top of schedule.rb..:

set :bundle_command, "/home/YOUR_USER/.rbenv/shims/bundle exec"
Juanse Cora
  • 755
  • 9
  • 19