Edit : I just noticed that the user replied to his own post, but I will leave it if someone encounters a similar problem. I found this helpful for some.
I ran into this and found that this is a solution for Ruby scripts.
Ruby must be run in a specific environment. RVM solves this problem by searching for the ruby environment file for a specific version of ruby, which sets all the necessary environment variables. For example, if you have patch 448 for ruby 1.9.3, you can look at the environment file that was received:
cat /usr/local/rvm/environments/ruby-1.9.3-p484 export PATH="/usr/local/rvm/gems/ruby-1.9.3-p484/bin:/usr/local/rvm/gems/ ruby-1.9.3-p484@global /bin:/usr/local/rvm/rubies/ruby-1.9.3-p484/bin:$PATH" export GEM_HOME='/usr/local/rvm/gems/ruby-1.9.3-p484' export GEM_PATH='/usr/local/rvm/gems/ruby-1.9.3-p484:/usr/local/rvm/gems/ ruby-1.9.3-p484@global ' export IRBRC='/usr/local/rvm/rubies/ruby-1.9.3-p484/.irbrc' unset MAGLEV_HOME unset RBXOPT
(Note: my rvm installation was in /usr/local/.. but your installation may be in a different place. Use which ruby to find out where your ruby is installed)
Here you can see that it sets PATH and some other important environment variables. When you rvm use ruby-1.9.3-p448 , rvm actually receives this file in the background.
Cron runs are non-interactive sessions, which means that they do not have a “live” user logged in before the session. When you do this manually and start an interactive session, all this will take care of you, but for a non-interactive session, he does not know what the shell is or where to find the path to the environment. Maybe someone with more knowledge can give a technical explanation of why.
In any case, to get around this, add this to the top of your crontab:
SHELL=/bin/bash BASH_ENV=/home/gigawatt/.bashrc * * * * * /home/gigawatt/.rvm/rubies/ruby-2.0.0-p247/bin/ruby /home/gigawatt/drbronnersbot/drbronnersbot.rb
This tells the non-interactive cron user which shell to use, and then tells the source .bashrc . What is in the .bashrc ? Good question, you should add this line -
source /usr/local/rvm/environments/ruby-1.9.3-p484
(Replace your own ruby path again). Basically, you manually select the environment file that rvm might find for you. This is a way to get cron to use a specific gem environment or gemset.
It should work with these two changes.
Edit2 : on Ubuntu and similar systems by default .bashrc often contains something like
# If not running interactively, don't do anything case $- in *i*) ;; *) return;; esac
As the commentary suggests, the file will not run in a non-interactive / cron session. Anything you add below this line will fail.
In this case, either place the source command above this line, or simply use another file together, for example, ~/.cronrc .