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

Applications/questions using Raspberry Pi with Seeed products, please post it here.

Moderators: lily.li, violet, salmanfarisvp

Post Reply
User avatar
salmanfarisvp
Pre-kindergarten
Pre-kindergarten
Posts: 22
Joined: Sun May 20, 2018 2:02 am
Are you a staff member of seeedstudio?: no
Which products/projects are your favorite?: Linklt One , BeagleBone Green , ReSpaker
Contact:

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

Post by salmanfarisvp » Sat May 04, 2019 5:39 pm

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

User avatar
salmanfarisvp
Pre-kindergarten
Pre-kindergarten
Posts: 22
Joined: Sun May 20, 2018 2:02 am
Are you a staff member of seeedstudio?: no
Which products/projects are your favorite?: Linklt One , BeagleBone Green , ReSpaker
Contact:

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

Post by salmanfarisvp » Mon May 06, 2019 3:00 pm

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.

Post Reply