从 rc.local 启动时未运行 Bash 脚本

Lal*_*mar 3 startup bash

我写了一个简单的 bash 脚本:

#!/bin/bash
echo "hi" > log
exit 0
Run Code Online (Sandbox Code Playgroud)

使其可执行并成功运行。我将 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
Run Code Online (Sandbox Code Playgroud)

rc.local 是可执行的:

/$ ls -l /etc/rc.local
-rwxr-xr-x 1 root root 349 Aug  1 13:19 /etc/rc.local
Run Code Online (Sandbox Code Playgroud)

什么工作:

1.我直接放入echo "hi" > /home/katph/logrc.local,就可以了。意思是rc.local在启动时运行。

2.如果我用脚本手动运行rc.local,日志文件被正确创建。

有什么建议吗?我正在运行 Kubuntu14.04。

Cyr*_*rus 6

代替

log
Run Code Online (Sandbox Code Playgroud)

通过绝对路径

/home/katph/log
Run Code Online (Sandbox Code Playgroud)

例如

#!/bin/bash
echo "hi" > /home/katph/log
exit 0
Run Code Online (Sandbox Code Playgroud)