I'm trying to run a cron job using Gems. I've installed ruby via RVM and when I require a gem it breaks the cron job. I've tried requiring two totally different gems, PG / Pry, and when I require either, the cronjob doesn't complete. Here is the "testing code" that works fine:
open('/home/log.log', 'a') do |f|
f.puts Time.now.to_s
end
Here is how I setup the cronjob:
* * * * * /usr/local/rvm/rubies/ruby-2.0.0-p247/bin/ruby /home/test1.rb
I can see new output every minute. And when I add a require gem line at the top, it then breaks, but only when run through cron:
require 'pg'
open('/home/log.log', 'a') do |f|
f.puts Time.now.to_s
end
The cronjob runs (I can see it execute in the sys log), but never completes (no output ever makes it into the text file). I've tried this on two separate servers one Debian, one CentOS, and both have the same issue. Oddly enough this only affects the cron job, if I run the same ruby file from console: /home/test1.rb it will work just fine.
Any help would be great.