2014-01-14 91 views
0

我們希望從cron作業運行Rails腳本(例如rails runner -e生產腳本/ test.rb),但它會自動失敗。該腳本在從命令行運行時獨立運行。在cron工作中運行Rails腳本?

這裏是我們的crontab行:(此設定在晚上11:40)

45 23 * * * rails runner -e production /home/t/T/script/ia.rb 

我們做錯了什麼在運行這個Rails的從cron作業腳本?

謝謝!

日誌文件的內容(服藥後伊萬的建議):

[[email protected] T]# cat script/script.log 
Usage: 
    rails new APP_PATH [options] 

Options: 
    -r, [--ruby=PATH]   # Path to the Ruby binary of your choice 
           # Default: /usr/local/bin/ruby 
    -d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db) 
           # Default: sqlite3 
    -b, [--builder=BUILDER]  # Path to an application builder (can be a filesystem path or URL) 
    -m, [--template=TEMPLATE] # Path to an application template (can be a filesystem path or URL) 
     [--dev]     # Setup the application with Gemfile pointing to your Rails checkout 
     [--edge]    # Setup the application with Gemfile pointing to Rails repository 
     [--skip-gemfile]  # Don't create a Gemfile 
    -O, [--skip-active-record] # Skip Active Record files 
    -T, [--skip-test-unit]  # Skip Test::Unit files 
    -J, [--skip-prototype]  # Skip Prototype files 
    -G, [--skip-git]   # Skip Git ignores and keeps 

Runtime options: 
    -f, [--force] # Overwrite files that already exist 
    -p, [--pretend] # Run but do not make any changes 
    -q, [--quiet] # Supress status output 
    -s, [--skip]  # Skip files that already exist 

Rails options: 
    -v, [--version] # Show Rails version number and quit 
    -h, [--help]  # Show this help message and quit 

Description: 
    The 'rails new' command creates a new Rails application with a default 
    directory structure and configuration at the path you specify. 

Example: 
    rails new ~/Code/Ruby/weblog 

    This generates a skeletal Rails installation in ~/Code/Ruby/weblog. 
    See the README in the newly created application to get going. 
+3

日誌中的所有輸出的地方。所以我們可以看到究竟是什麼失敗。 –

+0

嘗試使用rails腳本的完整路徑,並確保運行cron腳本的用戶可以讀取'/ home/t/T/script/ia.rb' – eugen

+0

我們內部有日誌語句,但沒有顯示任何內容,@ IvanDenisov。 – Crashalot

回答

0

在工作中,在服務器上,我們運行與軌任務:

0 6 * * * bash -lc "cd /some_path && bundle exec rake RAILS_ENV=production some_task" 

也許你需要的慶典-lc一部分,裏面的所有命令「」

+0

「bash -lc」做什麼? – Crashalot

+1

你正在執行一個新的bash實例,用-c告訴它在字符串上運行該命令,檢查文件是否也是-l http://www.gnu.org/software/bash/manual/bashref.html#調用-Bash,如果你的服務器沒有bash,你可以使用任何終端 – arieljuod

0

附上您的命令到報價或使用反斜槓鏡像空間

45 23 * * * "rails runner -e production /home/t/T/script/ia.rb" 

45 23 * * * rails\ runner\ -e\ production\ /home/t/T/script/ia.rb 

代替

45 23 * * * rails runner -e production /home/t/T/script/ia.rb 
+0

爲什麼保留空格? – taro

+0

嗯,添加雙引號只會導致一個空的日誌文件...其他建議? – Crashalot

+0

對不起,只是沒有時間檢查所有可能的選項,但我打賭其中一個或組合將工作。 另請試試'\'rails runner -e production/home/t/T/script/ia。rb \'' –