原文:https://www.magentonotes.com/ubuntu-config-autostart-shell-script.htmlhtml
/etc/rc.local腳本是一個ubuntu開機後會自動執行的腳本,咱們能夠在該腳本內添加命令行指令。該文件須要root權限才能修改。該腳本具體格式以下,shell
注意,必定要將命令添加在 exit 0以前,好比我用VirtualBox啓動Ubuntu虛擬機,虛擬機上配置的 網絡鏈接是橋接模式,但Ubuntu每次啓動後,網絡ubuntu
都鏈接不上,須要啓動後,本身再執行NetworkManager命令,這裏,咱們就能夠將這個命令的執行放在/etc/rc.local裏面,bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# add by zhj,啓動網絡鏈接
NetworkManager
exit
0
|
要注意的是,/etc/init.d/目錄下的腳本的內容是有格式要求的,不能隨便寫,具體格式本身在網上搜吧網絡
1,新建個腳本文件new_service.shthis
1
2
3
4
|
#!/bin/bash
# command content
exit
0
|
2,設置權限spa
1
|
sudo
chmod
755 new_service.sh
|
3,把腳本放置到啓動目錄下命令行
1
|
sudo
mv
new_service.sh
/etc/init
.d/
|
4,將腳本添加到啓動腳本
執行以下指令,在這裏90代表一個優先級,越高表示執行的越晚code
1
2
|
cd
/etc/init
.d/
sudo
update-rc.d new_service.sh defaults 90
|
1
|
sudo
update-rc.d -f new_service.sh remove
|