Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Raspberry Pi rc.local不执行_Python_Linux_Startup - Fatal编程技术网

Python Raspberry Pi rc.local不执行

Python Raspberry Pi rc.local不执行,python,linux,startup,Python,Linux,Startup,我试图在启动时使用rc.local文件在我的Raspberry Pi上执行python温度监控脚本,但在多次尝试后,我都无法让它正常工作。当前我的rc.local如下所示: #!/bin/sh # # 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

我试图在启动时使用rc.local文件在我的Raspberry Pi上执行python温度监控脚本,但在多次尝试后,我都无法让它正常工作。当前我的rc.local如下所示:

#!/bin/sh
#
# 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.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

# start the temperature monitoring program
python /home/pi/TemperatureMonitoring/TempMonitor.py >> /var/log/rc.local.log 2>&1 &

exit 0
如您所见,我将其设置为将python输出记录到一个文件中,但是在启动期间根本不会创建该文件

检查rc本地服务的状态,我得到以下输出:

pi@raspberrypi:~ $ systemctl status rc-local.service
● rc-local.service - /etc/rc.local Compatibility
   Loaded: loaded (/lib/systemd/system/rc-local.service; static)
  Drop-In: /etc/systemd/system/rc-local.service.d
           └─ttyoutput.conf
   Active: failed (Result: exit-code) since Mon 2017-03-27 12:03:53 CEST; 44s ago
  Process: 565 ExecStart=/etc/rc.local start (code=exited, status=203/EXEC)

Warning: Unit file changed on disk, 'systemctl daemon-reload' recommended.
我已将rc.local文件设置为可执行文件,权限看起来正常:

pi@raspberrypi:~ $ ls -l /etc/rc.local
-rwxr-xr-x 1 root root 549 Mar 27 12:03 /etc/rc.local
此外,当我尝试从终端以root用户身份运行rc.local时,它会正确执行,并创建日志文件(即使打开时它是空的):

另外,这里是这个输出(我在研究这个问题时看到这个命令,我不确定它是做什么的):

任何帮助都将不胜感激

编辑:

这是syslog文件引导序列中rc.local似乎失败的部分:

Mar 27 13:48:54 raspberrypi systemd[1]: Starting /etc/rc.local Compatibility...
Mar 27 13:48:54 raspberrypi systemd[1]: Starting Network is Online.
Mar 27 13:48:54 raspberrypi systemd[1]: Reached target Network is Online.
Mar 27 13:48:54 raspberrypi systemd[1]: Starting LSB: Start NTP daemon...
Mar 27 13:48:54 raspberrypi systemd[568]: Failed at step EXEC spawning /etc/rc.local: Exec format error
Mar 27 13:48:54 raspberrypi systemd[1]: Started System Logging Service.
Mar 27 13:48:54 raspberrypi systemd[1]: rc-local.service: control process exited, code=exited status=203
Mar 27 13:48:54 raspberrypi systemd[1]: Failed to start /etc/rc.local Compatibility.
Mar 27 13:48:54 raspberrypi systemd[1]: Unit rc-local.service entered failed state.

#!/bin/sh in/etc/rc.本地更改为#/bin/bashNothing不幸地发生了变化(相同的203状态码,等等)。你能发布rc.local吗?似乎粘贴到这里太长了,但与我在原始帖子中粘贴的内容相比,我唯一改变的是#!bin/bash,我已经更改了python脚本的名称(我创建了一个非常简单的测试脚本,以确保这不是问题的原因)。
pi@raspberrypi:~ $ sudo /etc/init.d/rc.local start
[....] Starting rc.local (via systemctl): rc.local.serviceWarning: Unit file of rc.local.service changed on disk, 'systemctl daemon-reload' recommended.
Job for rc-local.service failed. See 'systemctl status rc-local.service' and 'journalctl -xn' for details.
 failed!
Mar 27 13:48:54 raspberrypi systemd[1]: Starting /etc/rc.local Compatibility...
Mar 27 13:48:54 raspberrypi systemd[1]: Starting Network is Online.
Mar 27 13:48:54 raspberrypi systemd[1]: Reached target Network is Online.
Mar 27 13:48:54 raspberrypi systemd[1]: Starting LSB: Start NTP daemon...
Mar 27 13:48:54 raspberrypi systemd[568]: Failed at step EXEC spawning /etc/rc.local: Exec format error
Mar 27 13:48:54 raspberrypi systemd[1]: Started System Logging Service.
Mar 27 13:48:54 raspberrypi systemd[1]: rc-local.service: control process exited, code=exited status=203
Mar 27 13:48:54 raspberrypi systemd[1]: Failed to start /etc/rc.local Compatibility.
Mar 27 13:48:54 raspberrypi systemd[1]: Unit rc-local.service entered failed state.