Ubuntu下新增開機啟動指令碼
阿新 • • 發佈:2019-01-28
1、方法一,編輯rc.loacl指令碼
Ubuntu開機之後會執行/etc/rc.local檔案中的指令碼,
所以我們可以直接在/etc/rc.local中新增啟動指令碼。
當然要新增到語句:exit 0 前面才行。
如:
sudo vi /etc/rc.local
然後在 exit 0 前面新增好指令碼程式碼。
2、方法二,新增一個Ubuntu的開機啟動服務。
如果要新增為開機啟動執行的指令碼檔案,
可先將指令碼複製或者軟連線到/etc/init.d/目錄下,
然後用:update-rc.d xxx defaults NN命令(NN為啟動順序),
將指令碼新增到初始化執行的佇列中去。
注意如果指令碼需要用到網路
update-rc.d: warning: /etc/init.d/test missing LSB information update-rc.d: see <http://wiki.debian.org/LSBInitScripts> Adding system startup for /etc/init.d/test ... /etc/rc0.d/K95test -> ../init.d/test /etc/rc1.d/K95test -> ../init.d/test /etc/rc6.d/K95test -> ../init.d/test /etc/rc2.d/S95test -> ../init.d/test /etc/rc3.d/S95test -> ../init.d/test /etc/rc4.d/S95test -> ../init.d/test /etc/rc5.d/S95test -> ../init.d/test
Removing any system startup links for /etc/init.d/test ... /etc/rc0.d/K95test /etc/rc1.d/K95test /etc/rc2.d/S95test /etc/rc3.d/S95test /etc/rc4.d/S95test /etc/rc5.d/S95test /etc/rc6.d/K95test