I was send here from Stackoverflow. Thank you for your help.
I am using a launcher.sh for a raspberrypi 4B with Raspi os x64 to start a python script in a python env on startup. But setting the environment is problematic.
The file (test.sh) looks like:
. envname/bin/activate
echo Hi Stackoverflow
or alternatively
#!bin/bash
. envname/bin/activate
echo Hi Stackoverflow
using sh test.sh
, correctly executes the shell script.
However, using it at launch with crontab
@reboot sh /home/pi/test.sh >/home/pi/logs/cronlog 2>&1
I get an error:
/home/pi/test.sh: 2: .: cannot open envname/bin/activate: No such file
How to properly set source @reboot
to start the env on startup?
p.s. sh is not the solution.
With bin/sh
and source envname/bin/activate
it does not work as Ubuntu apparently uses bash rather than sh, and if sh is used the source command is not known. Bash uses .
instead of source
Edit 1: Normal Ubuntu uses bash for shell, but maybe that is different on startup? Could that be a way?