As @Milliways has pointed out in his answer,
systemd is likely the more robust of your options. However, it's not the easiest or quickest. By that I only mean that if you're not familiar with
systemd, getting on top of the learning curve can take some time. I'd encourage you to do that (use
systemd), but there's no reason you can't make this work with an easier and quicker method now, and study
systemd in the background.
All that said, my answer is that you use
cron (specifically the
cron daemon (
crond) for this task. Know beforehand that
cron has some idiosyncrasies that may trip you up, depending upon what exactly it is that your program does. I'll try to cover some of those - let's begin:
1. Define your job in your
Open a terminal window (probably ssh in your case), and enter these commands:
This will explain what a
crontab is, and roughly how to use it. While you're reading,
man cron may also be helpful. When you finish reading, simply enter the single letter
q from the keyboard to get back to the command prompt. Next:
This will open your
crontab file in an editor. If you've not used it before, you may be prompted by the system to select an editor from a list. I'd recommend you select
nano unless you have other preferences.
When the editor opens, you will probably see some text in the file which is all comments (
# in first column). Move your insertion point to a blank line below the comments, and enter this:
@reboot (sleep 10; /home/pi/myScript.sh) >> /home/pi/cronjoblog.txt 2>&1
Here's the breakdown:
@reboot : run when the RPi boots
sleep 10 : wait for 10 seconds before running the next command
/home/pi/myScript.sh : run the script which is located in your (pi's) home dir
>> /home/pi/cronjoblog.txt : send all output (
stdout) to this logfile
2>&1 : add
stderr (error messages) to
stdout; all output from your program that would have gone to your terminal (
stdout) is merged for inclusion in the logfile created above.
Reboot your RPi. If this doesn't work (or even if it does) check the logfile at
/home/pi/cronjoblog.txt for clues.
Let us know if you have questions, and/or revise your question to add details.