2014-01-14 95 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 \'' –