linux設定開機自啟動指令碼的幾種方式介紹

2021-12-30 11:11:10 字數 1023 閱讀 7406

公司的開發機經常因為斷電被重啟,服務都得手動乙個乙個啟動,專門研究了下如何設定開機自動重啟指令碼。

最簡單粗暴的方式直接在指令碼/etc/rc.d/rc.local(和/etc/rc.local是同乙個檔案,軟鏈)末尾新增自己的指令碼

然後,增加指令碼執行許可權

chmod +x /etc/rc.d/rc.local

第二種方式是在crontab中設定

crontab -e

@reboot /home/user/test.sh

也可以設定每次登入自動執行指令碼,在/etc/profile.d/目錄下新建sh指令碼,

/etc/profile會遍歷/etc/profile.d/*.sh

另外,幾個指令碼的區別:

(1) /etc/profile: 此檔案為系統的每個使用者設定環境資訊,當使用者第一次登入時,該檔案被執行. 並從/etc/profile.d目錄的配置檔案中蒐集shell的設定。

(2) /etc/bashrc: 為每乙個執行bash shell的使用者執行此檔案.當bash shell被開啟時,該檔案被讀取(即每次新開乙個終端,都會執行bashrc)。

(3) ~/.bash_profile: 每個使用者都可使用該檔案輸入專用於自己使用的shell資訊,當使用者登入時,該檔案僅僅執行一次。預設情況下,設定一些環境變數,執行使用者的.bashrc檔案。

(4) ~/.bashrc: 該檔案包含專用於你的bash shell的bash資訊,當登入時以及每次開啟新的shell時,該該檔案被讀取。

(5) ~/.bash_logout: 當每次退出系統(退出bash shell)時,執行該檔案. 另外,/etc/profile中設定的變數(全域性)的可以作用於任何使用者,而~/.bashrc等中設定的變數(區域性)只能繼承 /etc/profile中的變數,他們是」父子」關係。

(6) ~/.bash_profile: 是互動式、login 方式進入 bash 執行的~/.bashrc 是互動式 non-login 方式進入 bash 執行的通常二者設定大致相同,所以通常前者會呼叫後者。

centos設定開機自啟動指令碼

以前直接在 etc rc.local中寫入命令可執行,現在發現不起作用。mount中內容 bin bash chkconfig 2345 80 90 description mount mount t cifs o username administrator password uid 1002,g...

linux開機為使用者設定自啟動指令碼

新建乙個目錄用於存放開機啟動指令碼mkdir auto start 編輯 etc rc.local檔案 在exit 0前面輸入如下內容 filepath home pi auto start home pi auto start 代表本機中需要開機自啟動的指令碼目錄 files ls for fil...

redis開機自啟動指令碼 linux

目前redis放在home下的資料夾中,寫乙個指令碼,待系統啟動的過程中,去啟動該指令碼。指令碼 redis.sh bin sh home juepei downloads redis 3.0.0 src redis server home juepei downloads redis 3.0.0 ...