简体   繁体   English

在linux redhat中启动时启动shell脚本

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

I want to run one shell script during booting of my linux server having redhat. 我想在启动带有redhat的linux服务器的过程中运行一个shell脚本。

Below are the steps I followed to achieve this 以下是我为实现这一目标而采取的步骤

1) I have created script /home/user/script/test.sh 1)我创建了脚本/home/user/script/test.sh

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

2) I have made script file as executable using below command 2)我使用下面的命令将脚本文件作为可执行文件

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

3) I have created put test.sh file inside /etc/init.d directory 3)我在/etc/init.d目录中创建了put test.sh文件

4) I have made soft link for using below command 4)我使用下面的命令做了软链接

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

5) reboot the server 5)重启服务器

Another things I have tried is put below line inside /etc/rc.local file 我尝试的另一件事是在/etc/rc.local文件中放在下面的行

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

But still I am not able to execute code written inside test.sh file. 但是我仍然无法执行test.sh文件中编写的代码。

According to the RedHat documentation RUNNING ADDITIONAL PROGRAMS AT BOOT TIME , you can add commands to the /etc/rc.d/rc.local script. 根据RedHat文档RUNNING ADDITIONAL PROGRAMS AT BOOT TIME ,您可以向/etc/rc.d/rc.local脚本添加命令。

If you are not seeing anything, try turning on tracing in the rc.local script to see what is happening: 如果您没有看到任何内容,请尝试在rc.local脚本中启用跟踪以查看发生的情况:

set -x

and you can send the trace to a known log file if you want: 如果需要,您可以将跟踪发送到已知的日志文件:

exec 2>/tmp/logfile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM