I will show you how to execute an arbitrary program with a shell script when you start the Raspberry Pi. Also, I tried running the python file with a shell script to see if it was actually executed. Programs other than python can be executed by rewriting the shell.
・ People who want to execute some program when starting Raspberry Pi (or Linux) ・ What is a shell? People or people who are not very familiar with (For the shell, I hope you can read this commentary which can be read in about 3 minutes.)
Hard: Raspberry Pi 3 Model B + (If the OS is the same, I think it can be executed by the following method) OS : Raspbian GNU / Linux 10 (Note that you cannot use the following method on Windows !!)
Create autostart.sh in / usr / local / bin /.
pi@raspberrypi:~ $ sudo nano /usr/local/bin/autostart.sh
This time I want to execute hello.py (described later in 3.) in the / home / pi / directory, so autostart.sh makes the following changes and saves (ctrl + s). If you are worried about whether you can change or save it, enter the ↑ command again.
#!/bin/sh
python3 /home/pi/hello.py
In addition, give execute permission to the shell script.
pi@raspberrypi:~ $ chmod 755 /usr/local/bin/autostart.sh
Make changes to rc.local so that autostart.sh can be run at startup.
The specific changes are as follows. Only the last part of rc.local has been changed)
fi
exit 0
--After change
fi
autostart.sh
exit 0
Create hello.py in the / home / pi / directory.
print("hello, ivrc")
You can either use the GUI or sudo reboot from the terminal, so please reboot and check.
This time I did it with Raspberry pi, but if you change the way of writing the shell a little, you can do the same with Unix-like OS other than Raspbian and languages other than Python. I'm also studying Shell, so I'll do my best to write it on my own little by little.
I want to execute the script when starting Raspberry Pi --Qiita