2

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).

5

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.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
example:~% 
|improve this answer|||||
  • 1
    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
2

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

|improve this answer|||||
1

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.

|improve this answer|||||
0

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.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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