rc.local腳本
rc.local腳本是一個(gè)ubuntu開(kāi)機(jī)后會(huì)自動(dòng)執(zhí)行的腳本,我們可以在該腳本內(nèi)添加命令行指令。該腳本位于/etc/路徑下,需要root權(quán)限才能修改。
該腳本具體格式如下:
#!/bin/sh -e## rc.local## This script is executed at the end of each multiuser runlevel.# Make sure that the script will "exit 0" on success or any other# value on error.## In order to enable or disable this script just change the execution# bits.## By default this script does nothing. exit 0
注意: 一定要將命令添加在 exit 0之前
如何給ubuntu添加一個(gè)開(kāi)機(jī)啟動(dòng)腳本
1,新建個(gè)腳本文件new_service.sh
#!/bin/bash# command content exit 0
2,設(shè)置權(quán)限
sudo chmod 755 new_service.sh
3,把腳本放置到啟動(dòng)目錄下
sudo mv new_service.sh /etc/init.d/
4,將腳本添加到啟動(dòng)腳本
執(zhí)行如下指令,在這里90表明一個(gè)優(yōu)先級(jí),越高表示執(zhí)行的越晚
cd /etc/init.d/sudo update-rc.d new_service.sh defaults 90
移除Ubuntu開(kāi)機(jī)腳本
sudo update-rc.d -f new_service.sh remove
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注