linux開機自動執行 sh指令碼

2021-08-19 21:08:39 字數 1589 閱讀 2800

#!/bin/sh

#chkconfig: 2345 20 80

#description:server reboot.execute auto.sh

#client post port 80 redirect 9527

#sudo iptables -a prerouting -t nat -i eth0 -p tcp —dport 80 -j redirect —to-port 9527

#auto.sh log

dir=/home/linux-nice

echo

"execute auto.sh" > $dir/auto_log.txt

chkconfig命令檢查、設定系統的各種服務。這是red hat公司遵循gpl規則所開發的程式,它可查詢作業系統在每乙個執行等級中會執行哪些系統服務,其中包括各類常駐服務

等級0表示:表示關機

等級1表示:單使用者模式

等級2表示:無網路連線的多使用者命令列模式

等級3表示:有網路連線的多使用者命令列模式

等級4表示:不可用

等級5表示:帶圖形介面的多使用者模式

等級6表示:重新啟動

#!/bin/sh 告訴linux伺服器這是乙個.sh指令碼

**2345**對應linux伺服器的2345階段能執行auto.sh指令碼

20表示啟動優先順序序號 80表示關閉優先順序序號(就這個不太懂 有哪位大佬能提供資料嗎)

[root@vm_158_86_centos ~]# cd /etc/rc.d/init.d/ 進入該資料夾

[root@vm_158_86_centos init.d]# vi auto.sh 編寫指令碼

[root@vm_158_86_centos init.d]# vi auto.sh

[root@vm_158_86_centos init.d]# chmod +x auto.sh 給指令碼新增執行許可權

[root@vm_158_86_centos init.d]# chkconfig --add auto.sh 新增指令碼至開機自啟

[root@vm_158_86_centos init.d]# chkconfig auto.sh on 開啟

[root@vm_158_86_centos init.d]# sudo reboot 重啟

請事先建立好/home/linux-nice/auto_log.txt 檔案

然後重啟伺服器 sudo reboot

auto_log.txt是否輸出了」execute auto.sh」

結果列印出來了 說明開機自動執行了該指令碼

prefect

補充:

有可能linux系統沒有/etc/rc.d/init.d/ 資料夾 就在/etc/rc.local

sh /path/***.sh命令

centos7 開機自動執行sh

由於在centos7中 etc rc.d rc.local的許可權被降低了,所以需要賦予其可執行權 1 chmod x etc rc.d rc.local 賦予指令碼可執行許可權 假設 opt script autostart.sh是你的指令碼路徑,給予執行許可權 2 chmod x opt scr...

開機自動執行指令碼

需求 自己寫了乙個定時重啟linux的shell指令碼,想要在開機的時候自動執行該指令碼 該指令碼reboot.sh內容為 bin bash while 1 do currenthour date h currentmin date m currentsec date s if currenthou...

linux命令寫成sh指令碼並執行

unrar.sh指令碼編寫為 該指令碼功能是轉到 home目錄下,將 1.rar壓縮包解壓到當前資料夾 home下 123456為解壓密碼 bin sh cd home unrar e p123456 1.rar 執行sh指令碼 unrar.sh 如果報錯 bin sh m bad interpre...