ich habe folges Skript erstellt damit dieses den Upload des freien Speichers der SD Card zu einem MQTT Broker durchführt:
Code: Alles auswählen
[#!/usr/bin/env python3
import paho.mqtt.publish as publish
from subprocess import check_output
from re import findall
def get_space():
space = check_output(df -P / | tr -s " " " " | cut -d " " -f 4).decode("UTF-8")
return(findall("\d+\.\d+",space)[0])
def publish_message(topic, message):
print("Publishing to MQTT topic: " + topic)
print("Message: " + message)
publish.single(topic, message, hostname="192.168.1.31")
temp = get_space()
publish_message("Home/pi/Space", space)
Allerdings erhalte ich folgende Fehlermeldung:
df: Ungültige Option --
„df --help“ liefert weitere Informationen.
Traceback (most recent call last):
File "/home/pi/space.py", line 16, in <module>
temp = get_space()
File "/home/pi/space.py", line 7, in get_space
space = check_output(["df","-P / | tr -s " " " " | cut -d " " -f 4"]).decode("UTF-8")
File "/usr/lib/python3.7/subprocess.py", line 395, in check_output
**kwargs).stdout
File "/usr/lib/python3.7/subprocess.py", line 487, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['df', '-P / | tr -s | cut -d -f 4']' returned non-zero exit status 1.
Nomral lauter der Befehl zur Abfrage:
Code: Alles auswählen
df -P / | tr -s " " " " | cut -d " " -f 4
An was könntes es liegen?
Danke & Grüße
Thomas