There are some ways to run a script, application, or command when the system loads.

The easiest way is to add the following line to the crontab:

crontab -e

   @reboot /path/script.sh

OR

   @reboot user /path/script.sh

For some reason, it does not always work. It depends on the distribution and version of the system.

On some systems you can create a script and place it at /etc/init.d/ as executable. Give it a try!

A popular way was to insert the execution commands in /etc/rc.local but it disappeared in some distributions. So, let’s recreate it!

printf '%s\n' '#!/bin/bash' 'exit 0' | sudo tee -a /etc/rc.local
sudo chmod +x /etc/rc.local
sudo nano /etc/systemd/system/rc-local.service

Add this content:

[Unit]
 Description=/etc/rc.local Compatibility
 ConditionPathExists=/etc/rc.local

[Service]
 Type=forking
 ExecStart=/etc/rc.local start
 TimeoutSec=0
 StandardOutput=tty
 RemainAfterExit=yes
 SysVStartPriority=99

[Install]
 WantedBy=multi-user.target

Now enable the service to run when the system loads:

sudo systemctl enable rc-local

Done!

Edit the file /etc/rc.local and insert the commands you want to be executed between the lines as shown:

#!/bin/bash
   ...write the commands here...
exit 0

Reload the system to verify.