0

I added a line at the end of .bashrc to start a python program as I start up raspberry.

However the program is not automatically executed and it runs only after openning terminal.

So I would like to make the program to be run without having to open terminal.

Is there anybody here with a suggestion?

My configuration is not raspberry connected to computer and running by serial

But Raspberry connected directly to keyboard, mouse and monitor.

pb77
  • 19
  • 1
  • 5

2 Answers2

4

You shouldn't put scripts into .bashrc or .profile. This files are executed when you login in console every time, not when system startup. It could hang your login session, and make raspberry pi unable to log in to. And of course can be executet multiple times, one for each console session.

To run script at startup, when the script is not intended to run all the time, I suggest to use corntab:

# edit crontab config
$ crontab -e

# add line in crontab config file
@reboot /path/to/the/script arguments
# save

To run script that must start with startup and run all the time raspberry pi is running, you should create service. This way is much more complicated, but gives you control what and when is running, especially when you haven't direct access to raspberry pi.

Łukasz Jakubek
  • 366
  • 1
  • 9
1

.bashrc is NOT intended to run scripts.

It is run each time a non-login interactive shell is started and is used to configure the shell.
~/.bashrc: executed by bash(1) for non-login shells.

There are may ways of running scripts, depending on what you are trying to do. See https://raspberrypi.stackexchange.com/a/47537/8697 for an example.

Milliways
  • 62,573
  • 32
  • 113
  • 225