Writing a shell script in Ubuntu to start automatically at boot (recommended)

Writing a shell script in Ubuntu to start automatically at boot (recommended)

The purpose of writing scripts is to avoid having to manually start various services (also for laziness haha)

1. Enter the terminal and enter

Create a script file with the suffix .sh

touch test.sh

Editing Scripts

vim test.sh

test.sh script content

2. Write the test.sh script

 #!/bin/bash

### BEGIN INIT INFO
# Provides: test
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start test
# Description: start test
### END INIT INFO

#Write the script content here cd /home/Desktop/
./test.sh
exit 0

Start with #!/bin/bash and write the script content in the middle and end with exit0

3. Move the test.sh file to the /etc/init.d directory

Move files

sudo mv test.sh /etc/init.d/

Add permissions to the file

chmod +750 test.sh

Set automatic startup

sudo update-rc.d test.sh defaults

4. Such a startup automation script is completed

Summarize

The above is what I introduced to you about writing shell scripts in Ubuntu to automatically start the computer at boot. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • How to add and delete startup items in Ubuntu
  • How to set up a startup script on Ubuntu 14.04
  • Ubuntu boot auto-start service settings

<<:  MySQL 8.0.16 compressed package installation and configuration method graphic tutorial

>>:  Vue batch update dom implementation steps

Recommend

Solve the problem of setting Chinese language pack for Docker container

If you use docker search centos in Docker Use doc...

Detailed process of implementing the 2048 mini game in WeChat applet

Rendering Example Code Today we are going to use ...

Introduction to CSS style classification (basic knowledge)

Classification of CSS styles 1. Internal style --...

Three.js sample code for implementing dewdrop animation effect

Preface Hello everyone, this is the CSS wizard - ...

Tips on making web pages for mobile phones

Considering that many people now use smartphones, ...

How to use border-image to implement text bubble border sample code

During the development activity, I encountered a ...

Detailed explanation of MySQL slow log query

Slow log query function The main function of slow...

Detailed explanation of the workbench example in mysql

MySQL Workbench - Modeling and design tool 1. Mod...

How to recompile Nginx and add modules

When compiling and installing Nginx, some modules...

Several methods of calling js in a are sorted out and recommended for use

We often use click events in the a tag: 1. a href=...

Linux sudo vulnerability could lead to unauthorized privileged access

Exploiting a newly discovered sudo vulnerability ...

How to set up automatic daily database backup in Linux

This article takes Centos7.6 system and Oracle11g...