In some cases, it is necessary to execute your script when the system boots up. Such cases include the need to change the screen resolution, launch certain applications, and update a particular utility.
Running a script can be accomplished in a variety of ways. You can do this by using a graphical shell or the systemd initialization system, which is now used in almost all distributions.
The first thing to do is to create a script in a convenient place and execute it:
$ sudo gedit /path_to_script/script_name.sh
#!/bin/bash
echo "Hello world"
This script will display "Hello world" messages to the user. Once the program is ready, you need to make it executable. To do this, the following command is used:
$ sudo chmod ugo+x /path_to_script_name/script_name.sh
Next, in the main menu of the system you need to launch the "Automatically Run Applications" utility.
Click the "Add" button and enter the full path to the script file in the "Command" field. You can press the "Browse" button, find and select the script file and press "Add".
In the future, the program will be executed every time you start the Ubuntu graphical shell.
Use a special command to create a systemd service file
This command is:
sudo systemctl edit --force myscript
In this file you need to add the contents:
[Unit]
Description=My Script Service
After=multi-user.target
[Service]
Type=idle
ExecStart=/full/path/to/script/script_name.sh
[Install]
WantedBy=multi-user.target.
Next, in the line called ExecStart you need to fulfill one of the following requirements: specify the path to the script or command to be executed. After that the script is added to the autoloader:
$ sudo systemctl daemon-reload
$ sudo systemctl enable mysrcipt
The program will start after system initialization. For this purpose, you can use the "old" method: with the help of rc.local, the /etc/rc.local file is created and the path to it is written in the ExecStart line of the service file.
Apply the discount by inserting the promo code in the special field at checkout: