How to run script on startup on Ubuntu 20.04 Focal Fossa Server/Desktop - LinuxConfig.org

In this article you will learn how to run script ( python, bash etc. ) on startup on Ubuntu 20.04 Server/Desktop
This is a companion discussion topic for the original entry at https://linuxconfig.org/how-to-run-script-on-startup-on-ubuntu-20-04-focal-fossa-server-desktop

I believe that you are missing an important instruction in Step 1:

First, create a Systemd service file as in an example below:

[Unit]
After=network.service

[Service]
ExecStart=/usr/local/bin/disk-space-check.sh

[Install]
WantedBy=default.target
After: Instructs systemd on when the script should be run. In our case the script will run after network connection. Other example could be mysql.target etc.
ExecStart: This field provides a full path to the actual script to be executed on startup
WantedBy: Into what boot target the systemd unit should be installed
NOTE
For more information on how to create Systemd service unit execute the man systemd.unit command.

Namely, you should mention that when you create the example service it should be saved as a file, e.g., disk-space-check.service in /etc/systemd/system/.

While a close read of step 3 explains that, a novice might not understand what file to create where.

THANK you!

Otherwise you need to scroll to the bottom of the article, see where the file is, then scroll back up to get the contents…

1 Like