To run a command or program when Raspberry Pi is started, you need to add the commandRC. LocalFile. This is useful when you want to run the program directly without configuring it after Raspberry Pi is powered on, or do not want to start the program manually every time.
Another method to replace a scheduled task is to use cron and crontab.
Editing RC. Local (edit the RC. Local file)
On your Raspberry Pi, select a text editor to edit/Etc/rc. LocalFile. You must use the root permission for editing. For example:
sudo vim /etc/rc.local
Add the command after the annotation, but make sure thatExit 0This line of code is at the end, and then save the file and exit.
Warning (note)
If your command needs to run for a long time (such as an endless loop) or cannot exit after running, make sure that you add&Symbol to run the command in other processes, for example:
python /home/pi/myscript.py &
Otherwise, the script cannot end and Raspberry Pi cannot start. This&Symbol allows the command to run in a specified process, and then continue to run the START process.
In addition, make sure that the file name uses an absolute path instead of a relative path relative to your home directory. For example/Home/PI/myscript. pyInstead of usingMyscript. py.
Address: http://www.raspberrypi.org/documentation/linux/usage/rc-local.md
RC. Local file of Raspberry Pi (set startup)