1、方法一,編輯rc.loacl腳本
Ubuntu開機之後會執行/etc/rc.local文件中的腳本,
所以我們可以直接在/etc/rc.local中添加啓動腳本。
當然要添加到語句:exit 0 前面才行。
如:
sudo vi /etc/rc.local
/home/neo/test.sh
exit 0
然後在 exit 0 前面添加好腳本代碼。
2、方法二,添加一個Ubuntu的開機啓動服務。
如果要添加爲開機啓動執行的腳本文件,
可先將腳本複製或者軟連接到/etc/init.d/目錄下,
然後用:update-rc.d xxx defaults NN命令(NN爲啓動順序),
將腳本添加到初始化執行的隊列中去。
注意如果腳本需要用到網絡,則NN需設置一個比較大的數字,如99。
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
-----------------------------------------------------------------------------------------------------------
下面是桌面版開機子啓動程序(app)。需先安裝app之後
下面以firefox爲例:
第一步:安裝:sudo apt-get install firefox
第二步:設置,完整流程如下:
mkdir -p ~/.config/autostart
sudo cp /usr/share/applications/firefox.desktop ~/.config/autostart/
sudo chown username:group firefox.desktop
chmod 0755 firefox.desktop
sudo reboot -f
重啓之後會自動運行firefox
備註: rm ~/.config/autostart/firefox.desktop 即可取消開機自啓動。