脚本问题从/etc/rc.local运行

时间:2019-12-24 05:47:34

标签: bash debian raspbian

我试图在启动时从/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 / exiterr显示

0

如果我减少了睡眠时间,那么/ tmp / output会更长(超过6000行而不进入睡眠状态)。 有什么想法为什么脚本在启动后不久就会退出?

0 个答案:

没有答案
相关问题