1

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 !!

1
  • 1
    This isn't really a crontab problem, more a $PATH problem. May 13, 2014 at 14:11

1 Answer 1

2

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.

1
  • Thanks a lot @cjc, I added this - PATH=$PATH:/usr/local/bin it worked smoothly. Thanks !!
    – rtdp
    Dec 9, 2011 at 21:23

Not the answer you're looking for? Browse other questions tagged .