3

This question already has an answer here:

I want to run .py script:

python /home/project/manage.py slope_update

If I run it from shell it's OK, but in cron does not work:

*/10 * * * * root python /home/project/manage.py slope_update

What wrong?

I edit my /etc/crontab file from root


SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --repo$
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --repo$
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --repo$
#

*/10 * * * * root /usr/bin/python /home/project/manage.py slope_update

With user quanta help:

*/10 * * * * root /usr/bin/python /home/project/manage.py slope_update >> /tmp/foo.log 2>&1

cat foo.log

Unknown command: 'slope_update' Type 'manage.py help' for usage.

Why slope_update try to use as command, but must have as parameter If this "python /home/project/manage.py slope_update" run in terminal it's work. Why?

marked as duplicate by Iain, mdpc, Ladadadada, Rex, sysadmin1138 Jun 2 '14 at 21:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • "does not work" is worthless for diagnosis. – Ignacio Vazquez-Abrams Mar 10 '11 at 8:40
  • script not running but cron work) – Konstantin Mar 10 '11 at 9:06
  • As you have used the /etc/crontab then the root username is required. – Iain Mar 10 '11 at 9:13
  • I delete it just now, this is not problem – Konstantin Mar 10 '11 at 9:15
  • do you have any ideas? – Konstantin Mar 10 '11 at 16:34
2

Redirect the error to file will help you debug easier:

*/10 * * * * root python /home/project/manage.py slope_update >> /tmp/foo.log 2>&1
  • Unknown command: 'slope_update' Type 'manage.py help' for usage. :( – Konstantin Mar 10 '11 at 9:17
  • Why slope_update try to use as command, but must have as parameter – Konstantin Mar 10 '11 at 9:18
2

Try putting the full path to python in your crontab e.g.

*/10 * * * * root /usr/bin/python /home/project/manage.py slope_update

Edit:

The problem will be that the PATH in cron does not include the directory where python is installed (/usr/bin) so you need to supply the full path to python.

Edit Edit:

You are running this from your /etc/crontab ? If not then the root parameter is not required and may be causing problems.

Check email for mail from cron as it sends output from a job to you.

Check where your python lives, which python and adjust the path in the crontab accordingly.

  • This is not file, it's parameter. – Konstantin Mar 10 '11 at 8:29
  • If I run it from shell it's OK - problem isn't in path to files – Konstantin Mar 10 '11 at 8:30
  • @Konstantin: even if this isn't the problem you're having, cron doesn't necessarily run with the same PATH that an interactive shell does; you should always specify the full path to be sure. – nickgrim Mar 10 '11 at 8:37
  • doesn't work :( – Konstantin Mar 10 '11 at 8:44

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