As frequently stated here (and other places) rc.local
has been deprecated in Linux, and it is not recommended for use. Numerous problems in the use of rc.local
have been reported here; you should consider another approach.
In general, there are two approaches: systemd
and cron
. This answer shows the cron
approach.
Your question shows the following : sudo python3 /home/pi/videotest.py &
. Based on this I'll assume that root privileges are, or will be, required to run your script. If you find they are not required, you shouldn't use them - but more on that below:
1. Create/modify the crontab
file:
We'll use "root's crontab" since you've indicated your script requires root privileges. From the command line:
sudo crontab -e
This will open root's crontab
for editing. Before doing so, you may be prompted to designate which editor to use. If prompted to select an editor, choose nano
unless you're familiar with another one in the list.
If you have determined that root privileges are unnecessary, open your (user pi
) crontab as follows:
crontab -e
2. Edit the crontab
to start your script at boot time
You should now be in your editor with a view of the current version of the crontab
. Add the following line to the bottom (last line) of the file, then save and exit the editor:
@reboot /bin/sleep 10; /usr/bin/python3 /home/pi/videotest.py >> /home/pi/mycronlog.txt 2>&1
Here's what happens:
at boot time, cron
tries to execute this job
cron
will sleep
for 10 seconds - this gives the system time to get its resources started
after 10 seconds, cron
will call python3
to run your script located at /home/pi/videotest.py
any output from your script is re-directed to the "log" file at /home/pi/mycronlog.txt
; 2>&1
ensures that stdout
and stderr
both go to the designated "log" file.
3. reboot
and test
Check the contents of your "log" file at /home/pi/mycronlog.txt
for any error messages the script may have thrown, and adjust fire as necessary. Let us know if you have other questions, or something you don't understand.
systemd
would be the best way to go. You might find the follow article helpful: blog.usedbytes.com/2019/11/run-at-startup-without-rc.local