Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following entry in crontab:

* * * * * python -c "import datetime;" >> /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
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) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
datetime.datetime(2010, 2, 24, 19, 36, 21, 244853)

On the command line you do:

example:~% python -c "import datetime;"      
example:~% python -c "import datetime; print"
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

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

share|improve this answer

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

python -c "import datetime;" 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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.