Page 1 of 1
execute script by pi after startup
Posted: Mon May 01, 2017 3:29 pm
by JustM3
Hi,
I want to execute a script on my rpi3 after startup. I tried tot use /etc/rc.local and put this line between fi and exit0.
Code: Select all
sudo python /home/pi/ledmatrix/ledmatrix.py image.png &
The .png file is a image that displays on the matrix board.
When I put the line below in rc.local, it will show a test animation on the ledmatrix board after startup.
Code: Select all
sudo python /home/pi/ledmatrix/test_2.py &
Is there a way to execute the first code line after startup?
Re: execute script by pi after startup
Posted: Mon May 01, 2017 8:35 pm
by dwhite0
which shell are you running? try .bashrc?
Re: execute script by pi after startup
Posted: Tue May 02, 2017 6:05 am
by JustM3
dwhite0 wrote:which shell are you running? try .bashrc?
I feel stupid, but what does a shell do/how does it work? And how can I see witch shell is running and how do I change the running shell?
Re: execute script by pi after startup
Posted: Tue May 02, 2017 6:27 am
by jahboater
JustM3 wrote:
Code: Select all
sudo python /home/pi/ledmatrix/ledmatrix.py image.png &
The .png file is a image that displays on the matrix board.
Where is the .png file? perhaps put the full path in, something like this:-
Code: Select all
sudo python /home/pi/ledmatrix/ledmatrix.py /home/pi/image.png &
Re: execute script by pi after startup
Posted: Tue May 02, 2017 7:04 am
by RaTTuS
don't use rc.lcoal [well you can but
a) it runs as root so no sudo needed
b) its environment is different to yours
c) a lot of things may not be setup when it runs]
use .bashrc to auto run commands [auto login also helps]
Re: execute script by pi after startup
Posted: Tue May 02, 2017 7:34 am
by JustM3
jahboater wrote:Where is the .png file? perhaps put the full path in, something like this:-
The image is located in the same folder as the script is placed.
When I run the script manually (when I'm located in the folder) the Terminal, it wil work. It looks like:
Code: Select all
Sudo python ledmatrix.py image.png
Re: execute script by pi after startup
Posted: Tue May 02, 2017 7:52 am
by jahboater
Try this then:
Code: Select all
python /home/pi/ledmatrix/ledmatrix.py /home/pi/ledmatrix/image.png &
As noted above the environment is different, and its already root.
In you case it doesn't run in your home directory and so has no idea where the "ledmatrix" folder is - so you must give it the full path.
Re: execute script by pi after startup
Posted: Tue May 02, 2017 5:54 pm
by JustM3
RaTTuS wrote:
use .bashrc to auto run commands [auto login also helps]
Thanks for the respons! It helped me a bit further.
I tried to use .bashrc and it works as soon as I asses the terminal (by ssh). But I need the script to run automatically (almost) as soon as I power-up my raspberry pi. The place where I want to use it doesn't have network acces.
I tried to auto login, but somehow I can't get it fixed with Jessie.
Re: execute script by pi after startup
Posted: Tue May 02, 2017 6:13 pm
by JustM3
jahboater wrote:Try this then:
CODE: SELECT ALL
python /home/pi/ledmatrix/ledmatrix.py /home/pi/ledmatrix/image.png &
As noted above the environment is different, and its already root.
In you case it doesn't run in your home directory and so has no idea where the "ledmatrix" folder is - so you must give it the full path.
Thanks! After I used the full path in /etc/rc./local it will run automatically after booting.
I still want to see/learn if I can get the .bashrc running the same way (if it is posable), because you can quit it easy with "Ctrl+C" as soon as I connect to my pi.
Re: execute script by pi after startup
Posted: Wed May 03, 2017 7:14 am
by RaTTuS
edit .bashrc and at the end put
Code: Select all
if [ $(tty) == /dev/tty1 ]; then
./script
fi
where ./script is the script in the home directory [just put the commands direct in there]
this will then auto run whenever you log in and if it is on the first terminal then it will run
it will not run if you are on other terminals or via ssh
then using raspi-config
set your machine to auto login a terminal session
...
the better way to do it is via the systemd system and start a service on the terminal you want with input from that session with the user you want