So im trying to make a Python script that constantly tests if a services is running and output the status via a red LED. I have a script:
import RPi.GPIO as GPIO
import time
import os
import subprocess
GPIO.setmode(GPIO.BCM)
GPIO.setup(21, GPIO.OUT)
GPIO.output(21, False)
while True:
stream = os.popen('systemctl is-active smbd')
output = stream.readlines()
if "in" in output:
GPIO.output(21, True)
print ("in")
else:
GPIO.output(21, False)
print ("no")
print (output)
time.sleep(1)
when im running it though it can read the output of the systemctl check and outputs it via the print(output) but the if "in" in output can't detect the in as in Inactive. But if I set the output String output = inactive It can detect the "In". The print outputs:
['active\n'] or ['inactive\n']
According to the actual status. But if I enter this string into the script i get an error regarding the output. That it has an syntax error.
Inactiveit isinactive