Debugging Crontab Jobs

How to debug an issue of cron's not executing a given script -- or other?

By default cron mails its output to the user who ran it. You could look there.

It's very useful to redirect the output of scripts run by cron so that you can look at the results in a log file instead of some random user's local mail on the server.

Here's how you would redirect stdout and stderr to a log file:

cd /home/deploy/your_app/current; script/runner -e production ./script/my_cron_job.rb >> /home/deploy/your_app/current/log/my_file.log 2>&1

The >> redirect stdout to a file, and and the 2>&1 redirects stderr to stdout so any error messages will be logged as well.

Having done this, you will be able to examine the error messages to see what's really going on.

How would I go about debugging a cron job that executes the script, but the script seem to not complete?


  1. If I were going to guess the problem
    it was an environment issue (e.g.
    scrapy is not in the path).
  2. To debug, make sure your cron job is sending the standard out and standard error to a log file/and or syslog

How to hook a debugger to a python code running via django crontab?

You can put a breaking point debugger in the code using pdb or ipdb. Like this:

def some_function():
# some code
import pdb;pdb.set_trace() # or use ipdb
# rest of the code

Then in shell, run python manage.py crontab show to show cronjobs with ids, then run python manage.py crontab run <id>. It will hit the debugger, then you will hit the breaking point. Thus you can use debugger here.

How to debug a python script that is executed by crontab?

Answering your questions:

  1. because cron jobs run in a very different environment compared to your terminal. most likely cron jobs are executed with the different permissions and from a different folder, also you cannot rely on PATH variable being the same (or any other variable for that matter)

  2. that seems ok.

  3. your script is breaking in read_data(), once you fix this you'll see your debugging output

Finally, why it does not work and how to fix it. Since you haven't provided any meaningful sources, I'd say your read_data() function tries to access some data files using relative paths and fails, since the script is executed from a different folder. You should make sure all paths are absolute and the permissions are set to allow access to those files.

How to debug Cron Jobs on Google App Engine?

Cron log gets populated into the log of default service.

Instead of View link log of default service should be filtered for the Rake task route that the cron is calling.



Related Topics



Leave a reply



Submit