0

I checked a lot posts with the same title, but I can't get my python running via cron. I have several cron scripts already, which execute well, but not python.

Crontab runs as root.

I added following lines to crontab:

SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin

I have this line for the execution in crontab:

* * * * *  cd /var/www/usi/; /usr/local/bin/python3.6 /var/www/usi/usi.py

I tried a lot of variations:

  • added sudo in front of it to run as a different user
  • added bash to the line
  • executed the user profile before etc etc.

No results. No errors in system log.

Any ideas?

Using Debian8

Amyntor
  • 1
  • 1
  • 2
  • 4
    Try using `&&` instead of semicolon for separation - that way if changing directory fails you'll at least get a proper error in your crontab log. – zwer Jul 17 '17 at 17:30
  • Which OS and version do you use? Which file contains your crontab? – Cyrus Jul 17 '17 at 17:37
  • Changed it. Nothing wrong in syslog. I am using: Debian 8. Crontab under /var/spool/cron/crontabs/root – Amyntor Jul 17 '17 at 17:39
  • Add usi.py to your question. – Cyrus Jul 17 '17 at 17:52
  • Is is just this script, or does it fail to run any python program? Did you try a simple "Hello world"? – cdarke Jul 17 '17 at 18:23
  • Good point. From command line it works. Using cron I get nothing. Syslog shows no errors, but not any output from the python script. – Amyntor Jul 17 '17 at 18:39

1 Answers1

0

I found the error while putting the cron task into a separate shell script. I executed the script via cron and got an error. Simple typo. Did now saw any error before in syslog. :-(

It executes well with this in crontab now:

SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin

* * * * *  cd /var/www/usi/ && /usr/local/bin/python3.6 /var/www/usi/usi.py
Amyntor
  • 1
  • 1
  • 2