How to start our scripts at Ubuntu startup

Applications at startup

One of the positive things about Ubuntu is that allows us to create and run our own scripts that help us improve the functionality of the system, scripts that are easy to create and that we can make them run at any time during the session or simply at the start of any session.

To be able to do this there are two safe and fast ways that will make any newbie customize their Ubuntu with a couple of clicks and two or three copy and paste, do you dare?

How to insert scripts in our Ubuntu

The first and simplest method of all is the inclusion of the script in our login using a graphical application. For this we are going to System–> Preferences–> Applications at startup and in Add program at startup, the command field we fill it with the script in question that we have created. We save everything and when the system reboots, Ubuntu will load our scripts.

The second method that we can use in our Ubuntu is a bit more difficult but following these steps is easy to do. First we have to create our script. Once the script is created we copy it and paste it in the folder / Etc / init.d (to do this we must be root users). Once we have pasted this script, we have to give them permissions to run this file. This is done by opening a terminal in the folder and typing the following:

chmod +x mi-script.sh

Now we have the script ready and we only need to tell the system to read and execute the script that we have inserted in the folder, for this we execute the following command in the terminal:

update-rc.d mi-script.sh defaults 80

This will make system include script at system startup and with each user that is in that system, it does not matter if it is a system administrator or a simple user. How you can see it is a simple and simple operation to carry out, don't you think?


8 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Pedro said

    Very interesting!

    How to run a script as root? Because clearly if I put "sudo ..." in it, I won't be able to enter the password.

    Thank you!

    1.    Ernesto said

      Although 3 years have passed at the time of answering, I hope that someone else will find it helpful:
      you dispense with sudo ...
      it would look like this

      ./my-script.sh

  2.   Jose Villamizar said

    I have ubuntu 18.04 and I do exactly what you describe here and it just does not load anything, I must limit that the file is extension, sh, is it that I need some additional step for my version of ubuntu?

  3.   William said

    The same thing happens to me as Jose Villamizar. scripts do not run when restarting Ubuntu 18.04

  4.   papalapa said

    There are already three of us, I do what the article says but it does not run on startup

  5.   linuxx said

    The same thing happens to me, any solution?

  6.   Marce said

    create the file /etc/rc.local

    #! / bin / sh -e
    ##
    ## /etc/rc.local file
    ## This script runs at the end of the multiuser runlevel.
    ## Make sure this script ends with the line "exit 0" if it is successful
    ## or any other value if you have an error.
    # Enter under this line what you want to execute before starting the users.
    # —– end of file ——
    exit 0

    give execute permissions
    and then start the service
    systemctl start rc-local
    if it is not at the beginning, place it
    systemctl enable rc-local
    regards

    1.    Alexis said

      This was what I finally had results with and to this date with Ubuntu 22, to the rc.local file I added the calls to the scripts with

      sh '/myscriptpath/script.sh'

      and ready