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.
Asked
Active
Viewed 3,555 times
3 Answers
2
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?
Adam
- 123
- 4
-
1Look [here](https://askubuntu.com/a/1264589/906933) for a more elaborate answer – kanehekili Dec 29 '20 at 20:52
-
If that link makes you think you need "spark" it's just an example. Here's a [generic link] (https://linuxconfig.org/how-to-run-script-on-startup-on-ubuntu-20-04-focal-fossa-server-desktop) – So_about_that Dec 29 '20 at 23:22
1
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)
raj
- 9,367
- 2
- 16
- 42
0
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.
Tejas Lotlikar
- 2,875
- 5
- 16
- 26
Toly Antonov
- 1
- 1