0

I use a RaspberryPi 3 with UbuntuMate 16.04. On it, I want to start a little Python (3.5) program every midnight. For that I call a little shell script, so that I can change into the wanted directory comfortably.

crontab:

5 0 * * * /path/to/script/start.sh

start.sh (yes, it's executable):

#!/bin/bash

cd /path/to/wanted/workingDir/
python3.5 ControllerQueue.py
#also tried: python3.5 ControllerQueue.py &

Now if I execute the programm or script from the terminal, everything runs fine. But if I use the crontab it starts the script and stops right after. I also tried running the programm directly but get the same outcome. The paths are correct as I copied the workingDir path from the crontab-file and started it via the terminal.

Is there something I overlook?

Moe
  • 62
  • 10
  • I already had that added in my python script but thanks for the reference :) – Moe Sep 26 '18 at 11:51
  • Check the Environment `PATH` running from `cron`, add this line to your `start.sh`: `set|grep PATH >> /tmp/start.sh.log`. Verify if `python3.5` is in your `PATH`. – stovfl Sep 26 '18 at 12:07
  • Relevant: [how-to-get-cron-to-call-in-the-correct-paths](https://stackoverflow.com/questions/2388087/how-to-get-cron-to-call-in-the-correct-paths) – stovfl Sep 26 '18 at 12:31
  • You are right, python wasn't in the PATH my cronjobs were using. I added it but I still have the same problem. The python script starts for a second and dissapears again. – Moe Sep 26 '18 at 14:05
  • Add `>> /tmp/start.sh.log` to both lines in your `start.sh` and check the output. To catch error output do: [how-can-i-redirect-and-append-both-stdout-and-stderr-to-a-file-with-bash](https://stackoverflow.com/questions/876239/how-can-i-redirect-and-append-both-stdout-and-stderr-to-a-file-with-bash) – stovfl Sep 26 '18 at 14:42
  • Thank you very much. I got an error saying, that there is no display to connect to. I didn't think that I need to add support for that as the script doesn't show anything. – Moe Sep 26 '18 at 15:00

1 Answers1

0

As stofvl suggested, I saved the error output of my shell script. It turns out that I needed to add a display. My programm is divided into two scripts. One which provides a GUI and the other main application. The script only starts the main application, without the GUI, but it seems that this didn't matter.

This discussion helped me solve the problem.

Moe
  • 62
  • 10