【发布时间】:2014-02-02 04:58:45
【问题描述】:
我们想从 cron 作业中运行 Rails 脚本(例如 rails runner -e production script/test.rb),但它默默地失败了。当从命令行运行时,该脚本会自行运行。
这是我们的 crontab 中的一行:(设置在晚上 11:40)
45 23 * * * rails runner -e production /home/t/T/script/ia.rb
从 cron 作业运行这个 Rails 脚本时我们做错了什么?
谢谢!
日志文件内容(采纳Ivan的建议):
[root@newvps 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.
【问题讨论】:
-
在某处记录所有输出。所以我们可以看到到底是什么失败了。
-
尝试使用rails脚本的完整路径,并确保运行cron脚本的用户可以读取
/home/t/T/script/ia.rb -
我们内部有日志语句,但没有显示任何内容,@IvanDenisov。
-
我指的是 rails 可执行文件的路径,如 /usr/local/bin/rails 或安装该脚本的任何位置。
-
@Chashalot
45 23 * * * rails runner -e production /home/t/T/script/ia.rb > /path/to/log/file你的脚本没有被执行。这就是为什么你的内心日志什么也没说
标签: ruby-on-rails ruby-on-rails-3 cron crontab