Running a Python script from crontab

Philip Semanchuk philip at
Tue Dec 2 15:50:02 CET 2008

On Dec 2, 2008, at 9:35 AM, Astley Le Jasper wrote:

> I need help ... I've been looking at this every evening for over a
> week now. I'd like to see my kids again!
> I have script that runs fine in the terminal but when I try to run it
> in a crontab for either myself or root, it bails out.
> The trouble is that obviously I get no console when using crontab so
> can't see any traceback. I use logging which shows 'info' messages as
> the script is working, but no error messages. I've peppered it with
> debug messages to try to track it down to a line, but it stops it the
> middle of appending data to a list. I'd expect it to bail out when
> calling a module or reading/writing to a different file.
> Is there any way of getting more info from the app, like popping up a
> console while its running?
> my crontab is:
> 30 15 * * * cd /home/myusername/src && python

Here's what my crontab looks like on FreeBSD. (Your syntax may  
differ.) Note how I'm redirecting stdout and stderr to a log file --  
that helps debugging. Also, I'm setting an explicit shell and path  
just to make sure that e.g. Python is findable.


# min    hh    day   mon  dow
   */2     *      *     *    *  python /usr/local/foo/ >> / 
var/log/me/myscript.txt 2>&1


More information about the Python-list mailing list