![Bash 脚本未在 rc.local 启动时运行](https://linux22.com/image/982895/Bash%20%E8%84%9A%E6%9C%AC%E6%9C%AA%E5%9C%A8%20rc.local%20%E5%90%AF%E5%8A%A8%E6%97%B6%E8%BF%90%E8%A1%8C.png)
我写了一个简单的 bash 脚本:
#!/bin/bash
echo "hi" > log
exit 0
使其可执行并且成功运行。我将 rc.local 编辑为以下内容:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
/home/katph/test.sh
exit 0
rc.local 是可执行的:
/$ ls -l /etc/rc.local
-rwxr-xr-x 1 root root 349 Aug 1 13:19 /etc/rc.local
正在起作用的是:
1.我直接输入echo "hi" > /home/katph/log
rc.local,它可以正常工作。这意味着 rc.local 在启动时运行。
2.如果我使用脚本手动运行 rc.local,则日志文件将被正确创建。
有什么建议吗?我正在运行 Kubuntu14.04。
答案1
代替
log
通过绝对路径
/home/katph/log
例如
#!/bin/bash
echo "hi" > /home/katph/log
exit 0