Write a shell script in ubuntu to start automatically when booting (recommended)

The script is written so that you don’t need to manually start various services (also to be lazy, haha)

1. Enter terminal input

Create a script file with the suffix .sh

touch test.sh

Edit script

vim test.sh

test.sh write script content

2. Write test.sh script

 #! /bin/bash

### BEGIN INIT INFO
# Provides:     test
# Required-Start:  $remote_fs $syslog
# Required-Stop:   $remote_fs $syslog
# Default-Start:2345
# Default-Stop:016
# Short-Description: start test
# Description:    start test
### END INIT INFO

# Script content written 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 files

chmod +750 test.sh

Set automatic startup

sudo update-rc.d test.sh defaults

  1. Such a boot automation script is complete

to sum up

The above is a shell script written in ubuntu that the editor introduced to you to start automatically. I hope it will be helpful to you. If you have any questions, please leave me a message. The editor will reply to you in time. Thank you very much for your support to the ZaLou.Cn website!
If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!

Recommended Posts

Write a shell script in ubuntu to start automatically when booting (recommended)
How to write a confession program in python
How to start a blog with Hexo on Ubuntu 14.04
How to create a Python virtual environment in Ubuntu 14.04
Detailed steps to automatically set the line number in ubuntu16.04
How to install memcache and start it in ubuntu environment
How to create a Sudo user on Ubuntu [Quick Start]