Take the 2-minute tour ×

I have the following entry in crontab:

* * * * * python -c "import datetime; datetime.datetime.now()" >> /home/myname/pythoncron1.log

The pythoncron1.log file is being created but has nothing in it and the file modified date has not bee updated since the file was created. I was expecting to see a bunch of lines in the file, one for every minute that the cron job was is run.

Why might this not be working?

(You may have guessed, I'm trying to do something a little more complicated than the example above but I've narrowed the problem down to python apparently failing to run when being invoked by cron).

share|improve this question
add comment

4 Answers

up vote 5 down vote accepted

Just to clarify, do you have any print statements in your python script?

Running interactively you don't need them:

Python 2.6.1 (r261:67515, Jul  7 2009, 23:51:51) 
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2010, 2, 24, 19, 36, 21, 244853)

On the command line you do:

example:~% python -c "import datetime; datetime.datetime.now()"      
example:~% python -c "import datetime; print datetime.datetime.now()"
2010-02-24 19:38:59.639324
share|improve this answer
Of course! So it looks like my broader problem is not that python won't run... I feel another question coming on. –  d4nt Feb 24 '10 at 12:46
add comment

you might need to put the whole python path in e.g. /usr/bin/python

share|improve this answer
add comment

If in fact it isn't what Frenchie said, which it most likely is, it may be helpful to look at that users mail. Cron mails output from cron jobs to the user account of that crontab. That is why you often see STDOUT and STDERR piped to /dev/null, so they wont be mailed output they don't care about.

You can use the mail command as that user to check for mail with helpful output. Also, the /var/log/cron file may include helpful information.

share|improve this answer
add comment

python -c "import datetime; datetime.datetime.now()" doesn't output anything, so there is nothing to be outputted to the file.

Make sure the command you run actually outputs something on the command-line.

share|improve this answer
add comment

Your Answer


