How to set up Cron to trigger a Rake?

Posted December 22, 2013 7.6k views
Hello - I have a rake task that I'd like to schedule a cron to run. My Rails 4 droplet is running Ubuntu 12.10 (Nginx + Unicorn). Here's what I have in crontab: SHELL=/bin/bash PATH=/sbin:/bin/usr/bin HOME=/ MAILTO="" * * * * * /bin/bash -l -c 'source ~/.bash_profile && cd /home/rails && RAILS_ENV=production bin/rake populate:fetch_nr_songs' I get this error /etc/profile.d/ line 9: ps: command not found /etc/profile.d/ line 10: ps: command not found /usr/local/rvm/scripts/rvm: line 96: dirname: command not found ERROR: Missing proper 'which' command. Make sure it is installed before using RVM! Any fix would be much appreciated thanks

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
6 answers

Try deleting that line, does that fix it?
Now I get this error message:
/bin/bash: //.bash_profile: No such file or directory
That's because you have HOME set to /. Delete that line too.
Thanks Kamal for all the help. Unfortunately now the cron doesn't run at all, I don't even get emails with error messages :(

The crontab I've been editing is located in etc/default
Did it have all those variables by default? Try resetting it to how it was before you edited it and using crontab -e to edit the cron instead.
Thanks Kamal!!!! Removing those variables and changing my RAILS_ENV caused it work!
  • Hi Adrian, I know this is an old post, but i’m facing the same issue. What do you mean by “changing my RAILS_ENV”?

    Here is my crontab file:

    * * * * * cd /home/openproject/openproject-ce && /home/openproject/openproject-ce/bin/rake RAILS_ENV=production bundle exec jobs:workoff