从bash重复运行Python脚本

时间:2018-07-27 21:16:04

标签: python linux

我正在尝试运行此Python脚本:

import os

with open('check_door', 'r') as file:
    text_1 = file.readline()

with open('alert_check', 'r') as file2:
    text_2 = file2.readline()

if text_1 == 'locked' and text_2 == 'disabled':
    os.system('python sensor.py')

使用以下命令:watch -n 60 /home/pi/check_sensor.py 我收到这些错误:

/home/pi/check_sensor.py: 1: /home/pi/check_sensor.py: import: not found
/home/pi/check_sensor.py: 2: /home/pi/check_sensor.py: Syntax error: "(" unexpected

我在做什么错了?

1 个答案:

答案 0 :(得分:0)

您需要调用python解释器,就像直接运行脚本一样。

watch -n 60 "python /home/pi/check_sensor.py"