簡體   English   中英

在linux redhat中啟動時啟動shell腳本

[英]start shell script at boot time in linux redhat

我想在啟動帶有redhat的linux服務器的過程中運行一個shell腳本。

以下是我為實現這一目標而采取的步驟

1)我創建了腳本/home/user/script/test.sh

    #!/bin/bash
    echo "xyz" >> output

2)我使用下面的命令將腳本文件作為可執行文件

chmod +x /home/user/script/test.sh

3)我在/etc/init.d目錄中創建了put test.sh文件

4)我使用下面的命令做了軟鏈接

 ls -s /etc/init.d/test.sh /etc/rc.d/S15test.sh

5)重啟服務器

我嘗試的另一件事是在/etc/rc.local文件中放在下面的行

/bin/sh /home/user/script/test.sh

但是我仍然無法執行test.sh文件中編寫的代碼。

根據RedHat文檔RUNNING ADDITIONAL PROGRAMS AT BOOT TIME ,您可以向/etc/rc.d/rc.local腳本添加命令。

如果您沒有看到任何內容,請嘗試在rc.local腳本中啟用跟蹤以查看發生的情況:

set -x

如果需要,您可以將跟蹤發送到已知的日志文件:

exec 2>/tmp/logfile

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM