0

I would appreciate some help as I have read a dozen answers and have failed on all of them to run my program or script at boot.

I am running Buster Lite (no Gui) I have a program I wrote in C++ called myProg in //myFolder. It draws to the frame buffer. after logging in (as pi) I can run this program by typing "//myFolder/mpProg" I also have a script that runs this program myScript.sh I can run myProg and myScript.sh (thus they are executable)

I have tried putting //myFolder/myProg and //myFolder/myScript.sh before the exit 0 in rc.local. The raspi boots but does not run my program in either case.

Any suggestion would be greatly appreciated. thanks, Richard

2
  • 1
    while what you've attempted to achieve using rc.local is obsolete, it still should work. Perhaps your program is wrong ... or maybe the path ... why do you always refer to the path with // at the beginning? perhaps the issue is because It draws to the frame buffer - but without any sort of detail, the answer is a pineapple Jun 9 '20 at 1:35
  • Does the program should always run as a service, or does it regular finished after a short time?
    – Ingo
    Jun 9 '20 at 19:59
1

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 crontab:

Open a terminal window (probably ssh in your case), and enter these commands:

man crontab

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:

crontab -e

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 (stderr and stdout) is merged for inclusion in the logfile created above.

2. Test

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.