ubuntu中編寫shell腳本開機自動啓動

編寫腳本是爲了避免用手動去開啓各類服務(也是爲了偷懶哈哈)python

1.進入終端輸入linux

建立一個後綴爲.sh的腳本文件vim

touch test.sh

編輯腳本bash

vim test.sh

test.sh編寫腳本內容ide

 2.編寫test.sh腳本ui

 

1 #!/bin/bash
 2 
 3 ### BEGIN INIT INFO
 4 # Provides:          test
 5 # Required-Start:    $remote_fs $syslog
 6 # Required-Stop:     $remote_fs $syslog
 7 # Default-Start:     2 3 4 5
 8 # Default-Stop:      0 1 6
 9 # Short-Description: start test
10 # Description:       start test
11 ### END INIT INFO
12 
13 #此處編寫腳本內容
14 cd /home/Desktop/
15 ./test.sh
16 exit 0

以#!/bin/bash開頭 中間寫腳本內容 exit0結尾 code

3.移動test.sh文件到/etc/init.d目錄下ip

移動文件rem

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

給文件增長權限it

chmod +750 test.sh

設置開機自動啓動

sudo update-rc.d test.sh defaults

 4.這樣一個開機自動化腳本就完成咯

相關文章
相關標籤/搜索