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

在linux redhat中启动时启动shell脚本,linux,redirect,Linux,Redirect,我想在启动带有redhat的linux服务器时运行一个shell脚本 以下是我实现这一目标的步骤 1) 我已经创建了script/home/user/script/test.sh #!/bin/bash echo "xyz" >> output 2) 我已经使用下面的命令将脚本文件作为可执行文件 chmod +x /home/user/script/test.sh ls -s /etc/init.d/test.sh /etc/rc.d/S15test.sh 3

我想在启动带有redhat的linux服务器时运行一个shell脚本

以下是我实现这一目标的步骤

1) 我已经创建了script/home/user/script/test.sh

    #!/bin/bash
    echo "xyz" >> output
2) 我已经使用下面的命令将脚本文件作为可执行文件

chmod +x /home/user/script/test.sh
 ls -s /etc/init.d/test.sh /etc/rc.d/S15test.sh
3) 我已经在
/etc/init.d
目录中创建了put
test.sh
文件

4) 我已经为使用下面的命令做了软链接

chmod +x /home/user/script/test.sh
 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文档,您可以向
/etc/rc.d/rc.local
脚本添加命令

如果没有看到任何内容,请尝试在rc.local脚本中打开跟踪以查看发生的情况:

set -x
如果需要,您可以将跟踪发送到已知的日志文件:

exec 2>/tmp/logfile

看,它可能运行在你预期之外的其他地方。查找
/output
或更改脚本以写入绝对路径名(可能是更好的选择)。/etc/rc.local是/etc/rc.d/rc.local的软链接