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?
- If I were going to guess the problem
it was an environment issue (e.g.
scrapy is not in the path). - 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:
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)
that seems ok.
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
Colour Highlighting Output Based on Regex in Shell
How to Pass Parameters to a Bash Script
Check the Open Fd Limit for a Given Process in Linux
How to Get a List of Available Wireless Networks on Linux
Symbols from Convenience Library Not Getting Exported in Executable
Docker: Are Docker Links Deprecated
Changing Environment Variable of a Running Process
Crt1.O: in Function '_Start': - Undefined Reference to 'Main' in Linux
A General Linux File Permissions Question: Apache and Wordpress
What Is Global _Start in Assembly Language
Receiving Key Press and Key Release Events in Linux Terminal Applications
How to Reference Files Relative to Application Root in Node.Js
How to Filter Out All Unique Lines in a File
Multiple Websites on Nginx & Sites-Available