0

I'm trying to run a ruby script that I can run just fine using Ruby from my home directory, but that fails using cron. The beginning of the script autocheck.rb looks like this:

require 'rubygems'
require 'mechanize'
require 'json'
require "active_record"

ActiveRecord::Base.establish_connection(
  :adapter => "postgresql",
  :encoding => "utf8",
  :database => "depot_development",
  :pool => "5",
  :username => "depot",
  :password => "fake_pwd")

The crontab looks like this:

*/15 08-17 * * 1-5 ruby /home/user/autocheck.rb

I checked the other entries here relating to cron and rvm (presuming that's the problem; I'm using rvm and ruby version 1.9.3) but I couldn't figure out the solution. Any help would be appreciated.

1
  • Replace ruby for the full path of ruby in your system (/bin/ruby or something like that)
    – fedorqui
    Commented Apr 9, 2013 at 21:54

1 Answer 1

1

RVM has a command to setup schedules for you:

rvm cron command "*/15 08-17 * * 1-5" ruby /home/user/autocheck.rb
2
  • This didn't work, as written, but I eventually figured out one way to do it. I added this line to the beginning of the crontab shell, like so: SHELL=/home/user/.rvm/bin/rvm-shell
    – jumar
    Commented Apr 10, 2013 at 13:20
  • yes that will work, with one important note - it will use default ruby might have unexpected error when there is no default. As for the failing command - please open RVM ticket for it => github.com/wayneeseguin/rvm/issues
    – mpapis
    Commented Apr 10, 2013 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.