Run the Specified Command/Auto Run Command of Ubuntu/Linux

Source: Internet
Author: User
Keywords run command ubuntu linux run command linux run command on boot
In many cases, Ubuntu is required to execute some specified commands when booting, and the operation methods are recorded here.
Alibaba Cloud Simple Application Server:  Anti COVID-19 SME Enablement Program
$300 coupon package for all new SMEs and a $500 coupon for paying customers.

Create your own startup script in /etc/init.d/
# The file name mystart here can be modified to any name you like, but it must be placed in the /etc/init.d/ directory
cd /etc/init.d
sudo vim /etc/init.d/mystart.sh
Write the command that needs to be executed,
#!/bin/bash
### BEGIN INIT INFO
# Provides: tuzixini
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: self define auto start
# Description: self define auto start
### END INIT INFO
# The above part must also be written, followed by the command you need to boot to execute, here is to mount a hard disk
sudo mount /dev/sdb1 /opt/disk
Modify the script file permissions (replace mystart.sh in the command with the actual script file name)
sudo chmod 755 /etc/init.d/mystart.sh
Add boot start (replace mystart.sh in the command with the actual script file name)
sudo update-rc.d mystart.sh defaults 90
ok, complete, this command will be run automatically when the system is started later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.