Skip to content

RVM, Rake and Cron on Ubuntu

by admin on August 24th, 2011

Tennnngh! I read countless blog posts, tried numerous approaches that I found and rebuilt the server more than a couple times. And finally I found what the missing piece was for getting a rake command to run in cron with rvm.

Most of the results I found (on stackoverflow) flagged the solution as adding the path to your rvm in your line item in crontab. Something like /home/username/.rvm/gems/rake my_awesome_task… etc. I tried every variation of that I could think of and got the same results.

I dont use cron every day so this was a revelation to me. I found out that you can set variables, environment variables in your crontab file.

So the solution was very simple. Edit the crontab like this.

  1. crontab -e

Then at the top of the file (mine is the first line)

  1. SHELL = /home/wylie/.rvm/bin/rvm-shell

Then my commands:

  1. * 4 * * * /bin/bash -l -c ‘cd /path/to/app && RAILS_ENV=production rake mytask –silent’

Done.

Hope that saves someone some time.

2 Comments
  1. Juan Pemberthy permalink

    Thanks! you saved my day!

  2. Sean permalink

    Thank you so much! I wish it had saved me more time, but it ended my troubles. Strangely, if you pipe the error output to a log file, you’ll get “expr: syntax error” every time the job runs. However, the job still runs as far as I can tell.

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS