最近正在折騰寫一個開機自動安裝軟件的shell腳本,用於批量給系統安裝軟件,
特此記錄一個shell腳本開機自動執行的的方法:
大家可能都知道,在其他Linux發行版本如CentOs等在etc
目錄下會有一個rc.local
文件,這個文件是啟動加載文件,也就是說,在我們開機后,系統會檢查一遍這個文件,並且會自動執行里面寫入的命令;
那么,我們只需要把我們想開機自動執行的腳本的執行路徑寫在這里就可以實現開機自動執行。
以下是rc.local的截圖,里面的內容大概如下:
我們只需要把文件寫入最下邊就可以了。
注意:
rc.local
文件需要加上執行權限,chmod +x rc.local
但是,你可能發現你的deepin系統中沒有這個rc.local
文件,沒有關系,自己寫一個就可以啦,是可以正常執行的。可以直接復制以下內容:
vim /etc/rc.local
#!/bin/bash # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES # # It is highly advisable to create own systemd services or udev rules # to run scripts during boot instead of using this file. # # In contrast to previous versions due to parallel execution during boot # this script will NOT be run after all other services. # # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure # that this script will be executed during boot.
exit 0
需要執行的放在 exit 0 上邊就可以啦!
重啟試驗一下吧!