【发布时间】:2016-10-02 09:55:15
【问题描述】:
我一直在尝试在 Rpi 启动时启动 python 脚本,但到目前为止我尝试的所有方法都不起作用。
脚本是这个的一些版本:https://www.raspberrypi.org/learning/temperature-log/worksheet/:
#!/usr/bin/python
import os, sys
from subprocess import check_output
from re import findall
from time import sleep, strftime, time
def get_temp():
temp = check_output(["vcgencmd","measure_temp"]).decode("UTF-8")
temp = float(findall("\d+\.\d+",temp)[0])
return(temp)
while True:
log=open("cpu_temp.txt","a")
temp = get_temp()
log.write("{0} {1}".format(strftime("%Y-%m-%d %H:%M:%S"),str(temp))+" degreeC\r\n")
sleep(60)
log.close()
它本身就可以正常工作。我尝试编辑 crontab,有和没有 Python 的绝对路径,以及编辑 /etc/rc.local
我知道它不起作用,因为它应该创建一个文本文件并每分钟对其进行编辑,而且它不是在启动时创建的。我在 crontab 和 rc.local 中有其他正在运行的命令。
需要帮助!
【问题讨论】:
-
crontab可能以不同的权限在不同的环境和不同的文件夹中运行 - 您可能需要使用创建文件的完整路径。 -
尝试使用文件的绝对路径。
标签: python raspberry-pi crontab boot