I'm trying to run a simple ruby script on my old PPC machine running 10.5 in an RVM environment.
Searching on SO, I've followed the chosen answer from this post.
This is the line in cron as a result:
SHELL=/bin/bash
00 * * * * BASH_ENV=~/.bash_profile && /bin/bash -c '~/deggy/onlineGW.rb'
This command runs fine in Bash at the root of the user sam.
Here's the salient part of my script:
#!/usr/bin/env ruby
require 'open-uri'
require 'nokogiri'
...
Here's the output of the error from cron:
X-Cron-Env: <SHELL=/bin/bash>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=sam>
X-Cron-Env: <USER=sam>
X-Cron-Env: <HOME=/Users/sam>
Date: Mon, 6 Jan 2014 03:15:00 -0600 (CST)
/Users/sam/deggy/onlineGW.rb:3:in `require': no such file to load -- nokogiri (LoadError)
OK, since I'm running RVM I have set my default ruby to 1.9.3 and as I mentioned above, the command executes in Terminal but not in cron. Is there another environment in play?
So clearly, there's something I'm overlooking. Help me to see it, sam
Or you can simply try
rvm cron setup # let RVM do your cron settings
which worked for me. via https://coderwall.com/p/vhv8aw
I configured several different operating systems to work with a couple of CRON flavors and RVM.
I first tried RVM's official solution to the problem but didn't work under FreeBSD and Gentoo. I had to manually add all relevant paths as showed bellow but first type
crontab -e
in order to launch the crontab editor[1]:The above example is working under Gentoo GNU/Linux using fcron a more flexible, beautiful and powerful solution to standard cron, but will work with any cron.
[1] This command will open
crontab
with your default system editor.To load default RVM ruby environment for
cron
jobs, here is what I setup for user-mode RVM, assume the user isohho
, home folder is/home/ohho
. To edit, entercrontab -e
in command line:The last line is for testing
rails
(if installed) can be invoked properly. You should also check whether~/.bash_profile
loads the RVM environment (which is default for bash).A detail explanation of
SHELL
andBASH_ENV
can be found in Daniel's answer.