Ubuntu 开机自动运行命令
生活随笔
收集整理的這篇文章主要介紹了
Ubuntu 开机自动运行命令
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Ubuntu開機自動運行自定義的命令,可以采用兩種方式:
?
第一種shell腳本方式
1、進入 /etc/init.d/ 目錄
[root@Ubuntu ~]# cd /etc/init.d/2、新建一個自定義名稱的sh腳本,這里以 xxx?名稱為例建立一個 xxx.sh 的腳本
[root@Ubuntu /etc/init.d/]# vi XXX.sh # xxx為你的腳本文件名XXX.sh 腳本內(nèi)容,編輯好以后保存退出 :wq
### BEGIN INIT INFO # Provides: svnd.sh # Required-start: $local_fs $remote_fs $network $syslog # Required-Stop: $local_fs $remote_fs $network $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts the svnd.sh daemon # Description: starts svnd.sh using start-stop-daemon ### END INIT INFObt restart # 這里為需要執(zhí)行的命令注:腳本內(nèi)容必須包含?### BEGIN INIT INFO? ?......? ? ### END INIT INFO??
不然會報錯誤:missing LSB tags and overrides
3、賦予腳本權(quán)限
[root@Ubuntu /etc/init.d/]# sudo chmod 775 ./XXX.sh # xxx為你的腳本文件名4、然后執(zhí)行以下命令
[root@Ubuntu /etc/init.d/]# sudo update-rc.d XXX.sh defaults 90 # xxx為你的腳本文件名System start/stop links for /etc/init.d/bt.sh already exist.5、最后重啟系統(tǒng)即可:reboot
?
附:取消開機啟動腳本
[root@Ubuntu ~]# cd /etc/init.d # 進入/etc/init.d目錄[root@Ubuntu /etc/init.d/]# sudo update-rc.d -f XXX.sh remove # 移除腳本,XXX為你的腳本文件名?
?
第二種添加系統(tǒng)啟動腳本方式:
1、編輯/etc/下的rc.local腳本
vi /etc/rc.local2、然后把對應(yīng)的需要執(zhí)行的腳本寫在 exit 0 前面,如下圖所示
編輯好以后保存退出即可 :wq
?
總結(jié)
以上是生活随笔為你收集整理的Ubuntu 开机自动运行命令的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Docker服务编排详解——(六)
- 下一篇: 计算机组成原理 关于CPU中的LDAC和