I have a Rails script that I would like to run daily. I know that there are many approaches, and that the cron'd script/runner approach is not favored by some, but seems to meet my needs.
However, my script is not executing as planned.
My application runs in /data/myapp/current , and the script script/myscript.rb in script/myscript.rb . I can start it manually without problems as root with:
/data/myapp/current/script/runner -e production /data/myapp/current/script/myscript.rb
When I do this, a special log/myscript.log file ( log/myscript.log ) is logged as expected:
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
I am going to work with cron every morning at 4 a.m. root crontab:
$ crontab -l 0 4 * * * /data/myapp/current/script/runner -e production /data/myapp/current/script/myscript.rb
In fact, it looks like he was trying to log in as recently as this morning!
$ 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) ...
However, there is no entry in my log file, and the data it should update was not updated. Log file permissions (as a test) were even configured to write globally:
$ ls -lh total 19M ... -rw-rw-rw- 1 myuser apps 7.4K Mar 3 13:19 myscript.log ...
I work on CentOS 5.
So my questions are ...
- Where else can I look for information to debug this?
- Could this be a SELinux problem? Is there a security context that I could set or change that could solve this error?
Thanks!
Update
Thanks to Pavel and Luke. This turned out to be an environmental problem, and capturing stderr in a log file allowed me to find the error.
$ 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'
Adding the Ruby executable to the command did the trick:
$ 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