Search code examples
raspberry-picommand-line-interfaceraspbian

How to run foreground script after autologin to raspbian CLI


I have python script that runs in infinitve loop and gets input from keyboard. Works like a charm when I run it manually from CLI. I want to automate this process -> that it will start up automaticly after Rpi boot and login "pi" user.

I used raspi-config to setup autologin to CLI as "pi" user and then I want to run python script in foreground.

Right now Rpi boots -> login as pi user to CLI -> and waits for action. And here I want to have my script start

I tried to run it as a service or in crontab but it always runs in the background. I also tried running it through /etc/rc.local but it starts running before the login prompts which i don't want. I found some tutorials but all of them are for GUI and background processes. I thought that it will be quite easy but after several hours I decided to ask here.

My OS is

Distributor ID: Raspbian Description: Raspbian GNU/Linux 9.8 (stretch) Release: 9.8 Codename: stretch

I run script -> python keyboardinput.py


Solution

  • I would invoke your script from /home/pi/.bashrc Your script would run every time you login and a shell starts.