bash - 从 /etc/rc.local 运行的脚本问题
问题描述
我正在尝试在引导时从 /etc/rc.local 在无头 Raspberry Pi 4(Raspbian buster lite - 基于 Debian)上运行 bash 脚本。我在 Pi 3 上成功地做了类似的事情,所以我很困惑为什么 Pi 4 会行为不端 - 或表现不同。从 /etc/rc.local 执行的脚本会触发,但似乎只是以看似随机的间隔退出,而没有说明它被终止的原因。
为了测试它,我简化了脚本并将以下内容粘贴到名为 /home/pi/test.sh 的测试脚本中:
#!/bin/bash
exec 2> /tmp/output # send stderr from rc.local to a log file
exec 1>&2 # send stdout to the same log file
set -x # tell bash to display commands before execution
while true
do
echo 'Still alive'
sleep .1
done
然后我在退出行之前从 /etc/rc.local 调用它:
#!/bin/sh -e
#
# rc.local - executed at the end of each multiuser runlevel
#
# Make sure that the script will "exit 0" on success or any other
# value on error.
/home/pi/test.sh
echo $? >/tmp/exiterr #output exit code to /tmp/exiterr
exit 0
/tmp/output 的内容:
+ true
+ echo 'Still alive'
Still alive
+ sleep .1
+ true
+ echo 'Still alive'
Still alive
+ sleep .1
和 /tmp/exitrr 显示
0
如果我减少睡眠时间,/tmp/output 会更长(超过 6000 行没有睡眠)。任何想法为什么脚本在启动后不久就退出?
解决方案
推荐阅读
- react-native - 视图换行到下一行时如何使用marginTop?
- anaconda - 错误 anaconda_api.is_vscode_available:956
- postman - postman.setNextRequest() 中的目标请求无法设置环境变量
- autoconf - 为 r 包编写 `configure` 文件
- java - 多个分隔符,并希望使用正则表达式将其中一个分隔符包含在字符串中
- python - tensorflow,feed_dict 错误,ValueError:无法输入形状的值
- javascript - 如何将 LLVM IR br 转换回 while 循环
- unicode - 包含 45° 角的折线图的最佳 Unicode 字符
- c# - C# Returning the method in the same method
- c++ - 计算字符串 C++ 中每个字母的频率的最有效方法是什么?