The following config will discuss a basic example on how to execute shell script during a boot time on systemd Linux. There maybe various reason why you might want to execute shell script during Linux startup like for example to start a particular custom service, check disk space, create a backup etc.
The following example below will serve as a basic template to be later modified to suit your specific needs. In the example below we will check a disk space of a /home/
directory during a boot time and write a report to /root/
directory.
Systemd service unit
First, we need to create a systemd startup script eg.disk-space-check.service
and place it into /etc/systemd/system/
directory. You can find the example of such systemd startup script below:
[Unit] After=mysql.service [Service] ExecStart=/usr/local/bin/disk-space-check.sh [Install] WantedBy=default.target