2013-04-09 53 views
0

我想運行一個ruby腳本,我可以使用我的主目錄中的Ruby運行得很好,但是使用cron失敗。腳本autocheck.rb的開頭是這樣的:使用crontab執行導軌使用腳本

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") 

在crontab看起來像這樣:

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

我檢查這裏的其他條目有關cron和RVM(假設這就是問題所在,我使用rvm和ruby版本1.9.3)但我找不出解決方案。任何幫助,將不勝感激。

+0

更換'ruby'你的系統中ruby'的'完整路徑('/斌/ ruby​​'或類似的東西) – fedorqui 2013-04-09 21:54:22

回答

1

RVM已經爲你設置時間表的命令:

rvm cron command "*/15 08-17 * * 1-5" ruby /home/user/autocheck.rb 
+0

這沒像寫作一樣工作,但我最終想出了一個辦法。我將這行添加到crontab shell的開頭,如下所示:SHELL =/home/user/.rvm/bin/rvm-shell – jumar 2013-04-10 13:20:49

+0

是的,這將工作,一個重要的注意事項 - 它將使用默認的紅寶石可能會有意想不到的錯誤當沒有違約時。至於失敗的命令 - 請打開RVM票據=> https://github.com/wayneeseguin/rvm/issues/ – mpapis 2013-04-10 16:59:00