I'm using Ubuntu Server 20.04 for Raspberry Pi 4, I'm trying to get a .sh file to run at boot, so I can just plug the Pi in and it runs the script, but how do I do that.
3 Answers
systemctl
is what you're looking for. You'll need to install the script somewhere appropriate. Then, create a service file. Make sure that the file is executable (chmod +x /your/file.sh
).
More details can be found here: How do I run a single command at startup using systemd?
-
1
-
If that link makes you think you need "spark" it's just an example. Here's a [generic link] (linuxconfig.org/…) Dec 29, 2020 at 23:22
You can do it via cron. Create a file (with any name you choose) in directory /etc/cron.d
which contains the following:
@reboot root /path/to/your/file.sh
(the .sh file needs to be executable of course)
In most cases, you edit $ sudo nano /boot/config.txt
and add what you need to start on boot, here is another way in more detailed explanation, copy and paste to new browser tab.