0
votes

0/5 * * * * /bin/bash -l -c 'cd /home/mss/ruby/example && RAILS_ENV=development /usr/local/bin/bundle exec rake check_me_out --silent >> /tmp/cron_log.log 2>&1'

Above cron throws an error "bash: bundle: command not found..."

The command works just fine from the command line

Any help will be appreciated.

3
Any context about what you are trying to do before jumping straight into the code? - Darin Dimitrov
I would assume the user, as which the cron job runs does not know about the command bundle or has no access to it. - scones
Trying to rake a task in rails. See my comments above I am able to run it from my command line without any issues but not from the cron. - PackedUp

3 Answers

6
votes

Okay so I got this working. Cron does not load the profile settings. I had to load the bash_profile as part of the commands and now it works.

0/5 * * * * /bin/bash -l -c 'source ~/.bash_profile && cd /home/mss/ruby/example && RAILS_ENV=development bin/rake check_me_out --silent >> /tmp/cron_log.log 2>&1'

0
votes

I faced the same problem.

I had solved it when set correct RVM path in CRON:

** * * * /bin/bash -l -c 'cd /home/alex/Projects/my_app && source ~/.bash_profile && rvm use ruby-1.9.3-p194-perf && bundle exec rake RAILS_ENV=development my_tasks --silent >> /tmp/cron_log.log 2>&1'

0
votes

I also had the same issue when I set up cron on the AWS EC2 server. It was resolved by setting bundle path explicitly in the config/schedule.rb file.

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

This creates entry in the cron like:

30 1 * * * /bin/bash -l -c 'cd <app_path> && RAILS_ENV=beta /usr/local/bin/bundle exec rake 'task_name' --silent >> log/cron.log 2>&1'