7

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?

Konstantin
  • 71
  • 1
  • 1
  • 3

2 Answers2

4

Redirect the error to file will help you debug easier:

*/10 * * * * root python /home/project/manage.py slope_update >> /tmp/foo.log 2>&1
quanta
  • 50,327
  • 19
  • 152
  • 213
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.

user9517
  • 114,104
  • 20
  • 206
  • 289