Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to debug an issue of cron's not executing a given script -- or other?
    primarykey
    data
    text
    <p>I have a Rails script that I would like to run daily. I know there are many approaches, and that a cron'd <code>script/runner</code> approach is frowned upon by some, but it seems to meet my needs.</p> <p>However, my script is not getting executed as scheduled.</p> <p>My application lives at <code>/data/myapp/current</code>, and the script is in <code>script/myscript.rb</code>. I can run it manually without problem as <code>root</code> with:</p> <pre><code>/data/myapp/current/script/runner -e production /data/myapp/current/script/myscript.rb </code></pre> <p>When I do that, the special log file (<code>log/myscript.log</code>) gets logged to as expected:</p> <pre><code>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 </code></pre> <p>I have it set to run with <code>cron</code> every morning at 4 am. <code>root</code>'s crontab:</p> <pre><code>$ crontab -l 0 4 * * * /data/myapp/current/script/runner -e production /data/myapp/current/script/myscript.rb </code></pre> <p>In fact, it looks like it's tried to run as recently as this morning!</p> <pre><code>$ 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) ... </code></pre> <p>However, there is no entry in my log file, and the data that it should update has not been getting updated. The log file permissions (as a test) were even set to globally writable:</p> <pre><code>$ ls -lh total 19M ... -rw-rw-rw- 1 myuser apps 7.4K Mar 3 13:19 myscript.log ... </code></pre> <p>I am running on CentOS 5.</p> <p>So my questions are...</p> <ol> <li>Where else can I look for information to debug this?</li> <li>Could this be a SELinux issue? Is there a security context that I could set or change that might resolve this error?</li> </ol> <p>Thank you!</p> <p><strong>Update</strong></p> <p>Thank you to Paul and Luke both. It did turn out to be an environment issue, and capturing the <code>stderr</code> to a log file enabled me to find the error.</p> <pre><code>$ 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' </code></pre> <p>Adding the specific Ruby executable to the command did the trick:</p> <pre><code>$ crontab -l 0 4 * * * /usr/local/bin/ruby /data/myapp/current/script/runner -e production /data/myapp/current/script/myscript.rb &gt;&gt; /data/myapp/current/log/cron.log 2&gt;&amp;1 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload