我有一个Rails脚本,我想每天运行。我知道有很多方法,并且某些方法令人不悦,但似乎满足了我的需求。如何调试cron不执行给定脚本的问题 - 或其他?
但是,我的脚本没有按计划执行。
我的应用程序位于/data/myapp/current
,脚本位于script/myscript.rb
。我可以毫无问题手动运行它为root
有:
/data/myapp/current/script/runner -e production /data/myapp/current/script/myscript.rb
当我这样做,特殊的日志文件(log/myscript.log
)被记录到预期:
Tue Mar 03 13:16:00 -0500 2009 Starting to execute script...
...
Tue Mar 03 13:19:08 -0500 2009 Finished executing script in 188.075028 seconds
我有它设置与运行cron
每天早上4点。 root
的crontab:
$ crontab -l
0 4 * * * /data/myapp/current/script/runner -e production /data/myapp/current/script/myscript.rb
事实上,它看起来像今天早上试图运行!
$ tail -100 /var/log/cron
...
Mar 2 04:00:01 hostname crond[8894]: (root) CMD (/data/myapp/current/script/runner -e production /data/myapp/current/script/myscript.rb)
...
Mar 3 04:00:01 hostname crond[22398]: (root) CMD (/data/myapp/current/script/runner -e production /data/myapp/current/script/myscript.rb)
...
但是,我的日志文件中没有条目,应更新的数据没有更新。日志文件的权限(作为测试)甚至被设置为全局可写:
$ ls -lh
total 19M
...
-rw-rw-rw- 1 myuser apps 7.4K Mar 3 13:19 myscript.log
...
我在CentOS运行5
所以我的问题是...
- 还能在哪里我寻找信息来调试这个?
- 这可能是SELinux问题吗?是否有可以设置或更改的安全上下文来解决此错误?
谢谢!
更新
谢谢你对保罗和卢克两者。它确实是一个环境问题,并且将stderr
捕获到日志文件使我能够找到该错误。
$ cat cron.log
/usr/bin/env: ruby: No such file or directory
$ head /data/myapp/current/script/runner
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/runner'
添加特定的Ruby可执行文件的命令做了伎俩:
$ crontab -l
0 4 * * * /usr/local/bin/ruby /data/myapp/current/script/runner -e production /data/myapp/current/script/myscript.rb >> /data/myapp/current/log/cron.log 2>&1
我一直在debian&ubuntu(vixie cron)/etc/cron.d中使用符号链接多年,没有任何问题。事实上,vixie cron似乎没有这样的选择。 – graywh 2012-09-24 15:09:10