How to set up Cron to trigger a Rake?

December 22, 2013 3.2k 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
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!
Have another answer? Share your knowledge.