我想在我的Raspberry Pi启动时运行bash脚本。该脚本如下所示:
# run the file
while :
do
echo Begin >> /home/pi/vueServer/stayalive/kochbuchsebastian/log.txt
node /home/pi/vueServer/stayalive/kochbuchsebastian/index.js
echo Finished >> /home/pi/vueServer/stayalive/kochbuchsebastian/log.txt
sleep 10
done
索引执行一些逻辑,并将index running
记录到输出日志文件中。当我从终端执行bash命令时,此方法有效:
bash /home/pi/vueServer/stayalive/kochbuchsebastian/kochbuchSebastian.sh
在rc.local
文件中,我添加了上面的行。
index.js看起来还有更多内容,但这是最重要的部分(当我从终端手动执行bash
时,它可以工作):
const now = new Date();
fs.appendFile(
'/home/pi/vueServer/stayalive/kochbuchsebastian/log.txt',
`${Utils.getFormatted(now)} : Executing index.js\n`,
(err) => {
if (err) console.error(err);
},
);
我期望以下输出:
Begin
Executing index.js
Finished
Begin
Executing index.js
Finished
etc.
这也是我手动执行bash脚本时发生的情况。 但是在Pi启动时会发生以下情况:
Begin
Finished
Begin
Finished
Begin
Finished
Begin
Finished
未执行index.js文件。
如果我从终端(bash kochbuchsebastian.sh
)运行kochbuchsebastian.sh,一切正常。为什么在启动Pi时不执行节点脚本?