I wrote a script for object detection and if I establish ssh connection to Raspberry Pi and run it from console, everything works fine. As I would like to start the script automatically on boot, I added the entry to the cron table:

@reboot cd /home/pi/workspace/counting-objects && python3 script.py

In the script, I have added following lines before and after import to check whether the import is the issue as I noticed the script was not running:

logger.info("[INFO] Importing libraries for openvino...")
from openvino.inference_engine import IENetwork, IEPlugin
logger.info("[INFO] libraries imported successfully")

In the log file, I saw the first line and the second line was missing, which means an error occurred while trying to import openvino library.

Does anyone know if there is a way to "emulate ssh connection environment" or anyhow solve this issue? The problem is that the issue cannot be reproduced if the script is ran from console.

  • 1
    the issue may be the difference between running it as user pi vs running it as root - there's many ways to run things on boot (cron isn't my choice, but whatever) - and each method has its own way of running as a chosen user - that's what I'd be looking for edit: removed link, because it was written by a numpty – Jaromanda X Jan 30 '19 at 7:41
  • 1
    You know you can probably see what the error is in the cron log? – Jaromanda X Jan 30 '19 at 8:20

Create a systemd unit file with:

rpi ~$ sudo systemctl --force --full edit myscript.service

In the empty editor insert these statements, save them and quit the editor:

Description=My script

ExecStart=/usr/bin/python3 /home/pi/workspace/counting-objects/script.py


If the script is running all the time in the background like a service and not only one short time at startup then just omit the two lines Type=oneshot and RemainAfterExit=yes.

Enable the service with:

rpi ~$ sudo systemctl enable myscript.service

Reboot and check the status with:

rpi ~$ systemctl status myscript.service
| 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.