Page 1 of 1

How to autorun a Python/Bash Script in headless mode.

Posted: Sat May 04, 2019 5:39 pm
by salmanfarisvp
I need to run a python script when Rpi is turn on, I was using a python virtual environment so I was created a script for the autorun and added on the .bashrc, but the script only starts when connecting a GUI or start new SSH session, it won't automatically start in headless mode.

Model: Raspberry Pi B
OS: Raspbian Strech

Thanks.

bash script :

Code: Select all

#!/bin/bash

source /home/pi/.profile
workon cv5
cd /home/pi/Desktop
python teste.py

Re: How to autorun a Python/Bash Script in headless mode.

Posted: Mon May 06, 2019 3:00 pm
by salmanfarisvp
Hi all,
found the solution, my goal is to run a python script that uses a virtual environment, so first wrote a bash script to automate the virtual environment setup then added bash script on them .bashrc

Code: Select all

#!/bin/bash
 
source /home/pi/.profile
workon cv
cd /home/pi/pi-reboot
python script_name.py
but the script won't run until I open the terminal (IDK why), and my application must need to work on the headless environment, so I disabled the GUI and enabled the autologin in the terminal via

Code: Select all

raspi-config  
Thank You.