Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This question already has an answer here:

I have cron running for rails application on EC2 instance, but it fails with error -

/bin/bash: bundle: command not found

if I run bundle command with ubuntu user or sudo user that works. I have added cron using crontab -e command.

Some Troubleshooting I did (displays same result with sudo as well) -

> which ruby
/usr/local/bin/ruby

> which bundle
/usr/local/bin/bundle

But if add these command as which ruby and which bundle in crontab and output it over logs, it shows -

Cron has -

* * * * * /bin/bash -l -c 'which ruby >> /home/ubuntu/logs/cron.log 2>&1'
* * * * * /bin/bash -l -c 'which bundle >> /home/ubuntu/logs/cron.log 2>&1'

Output -

/usr/bin/ruby
/bin/bash: bundle: command not found

so basically my cron is taking wrong ruby from system, what should I do to correct that ? I want to take ruby from my /usr/local/bin/ruby and then it can find bundle as well.

Thanks !!

share|improve this question

marked as duplicate by Iain, Jenny D, Cristian Ciupitu, Tom O'Connor May 13 at 14:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
This isn't really a crontab problem, more a $PATH problem. –  Tom O'Connor May 13 at 14:11

1 Answer 1

up vote 1 down vote accepted

You can specify the full path, as thince notes.

You should also be able to set the PATH at the top of your crontab:

PATH=$PATH:/usr/bin:/bin:/usr/local/bin
* * * * * ruby /home/ubuntu/scripts/ruby.rb >> /home/ubuntu/logs/cron.log 2>&1'
* * * * * bundle exec unicorn >> /home/ubuntu/logs/cron.log 2>&1'

Actually, I see that you have ruby installed in /usr/bin and /usr/local/bin. In that case, if you want a specific ruby, fully specify the path. With the cron as written above, because of the PATH order, you will execute /usr/bin/ruby and not /usr/local/bin/ruby.

share|improve this answer
    
Thanks a lot @cjc, I added this - PATH=$PATH:/usr/local/bin it worked smoothly. Thanks !! –  rtdp Dec 9 '11 at 21:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.