If you have a bash script that you need to run automatically every time your Ubuntu machine boots up, using a systemd service is the most robust method.
Creating a Systemd Service
- Create a new service file:
sudo nano /etc/systemd/system/myscript.service. - Add the execution instructions pointing to your script.
- Enable the service to run on boot:
sudo systemctl enable myscript.service. - Start the service immediately to test it:
sudo systemctl start myscript.service.