How to set up Cron to trigger a Rake?

  • Posted December 22, 2013

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


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

Thanks Kamal!!! Removing those variables and changing my RAILS_ENV caused it work!

Did it have all those variables by default? Try resetting it to how it was before you edited it and using <code>crontab -e</code> to edit the cron instead.

Thanks Kamal for all the help. Unfortunately now the cron doesn’t run at all, I don’t even get emails with error messages :( <br> <br>The crontab I’ve been editing is located in etc/default

That’s because you have HOME set to <code>/</code>. Delete that line too.

Now I get this error message: <br>/bin/bash: //.bash_profile: No such file or directory <br>

<blockquote>PATH=/sbin:/bin/usr/bin </blockquote> <br>Try deleting that line, does that fix it?