共計 1535 個字符,預計需要花費 4 分鐘才能閱讀完成。
這篇文章主要介紹了 Linux 如何配置開機自啟動執行腳本,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓丸趣 TV 小編帶著大家一起了解一下。
開機要啟動的腳本 qidong.sh
[root@c69-01 scripts]# vim /server/scripts/qidong.sh [root@c69-01 scripts]# cat /server/scripts/qidong.sh #!/bin/bash /bin/echo $(/bin/date +%F_%T) /tmp/qidong.log
方法一:修改 /etc/rc.local
/etc/rc.local,該文件為鏈接文件
[root@c69-01 ~]# ll /etc/rc.local lrwxrwxrwx. 1 root root 13 Feb 5 10:03 /etc/rc.local - rc.d/rc.local
修改 /etc/rc.local 文件
[root@c69-01 scripts]# tail -n 1 /etc/rc.local /bin/bash /server/scripts/qidong.sh /dev/null 2 /dev/null
重啟系統,查看結果
[root@c69-01 ~]# cat /tmp/qidong.log 2018-02-19_23:30:56
已開機自啟動該腳本
方法二:chkconfig 管理
刪除掉方法一的配置
[root@c69-01 ~]# vim /etc/init.d/test #!/bin/bash # chkconfig: 3 88 88 /bin/bash /server/scripts/qidong.sh /dev/null 2 /dev/null [root@c69-01 ~]# chmod +x /etc/init.d/test
添加到 chkconfig,開機自啟動
[root@c69-01 ~]# chkconfig --add test [root@c69-01 ~]# chkconfig --list test test 0:off 1:off 2:off 3:on 4:off 5:off 6:off
重啟系統,查看結果
[root@c69-01 ~]# cat /tmp/qidong.log 2018-02-19_23:30:56
2018-02-19_23:59:10
操作成功
關閉開機啟動
[root@c69-01 ~]# chkconfig test off [root@c69-01 ~]# chkconfig --list test test 0:off 1:off 2:off 3:off 4:off 5:off 6:off
從 chkconfig 管理中刪除 test
[root@c69-01 ~]# chkconfig --list test test 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@c69-01 ~]# chkconfig --del test [root@c69-01 ~]# chkconfig --list test service test supports chkconfig, but is not referenced in any runlevel (run chkconfig --add test)
感謝你能夠認真閱讀完這篇文章,希望丸趣 TV 小編分享的“Linux 如何配置開機自啟動執行腳本”這篇文章對大家有幫助,同時也希望大家多多支持丸趣 TV,關注丸趣 TV 行業資訊頻道,更多相關知識等著你來學習!
正文完