Files
Debian-Retzel/Level/Level5/watchdog.py

36 lines
684 B
Python

import time
import subprocess
import glob
import os
SCRIPT_NAME = "systemd-hdtob.py"
TIMEOUT = 600
def is_running():
try:
result = subprocess.run(
["pgrep", "-f", SCRIPT_NAME],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
return result.returncode == 0
except Exception:
return False
print("Watchdog gestartet...")
while not is_running():
time.sleep(1)
print("10min Timer ist aktiv")
for _ in range(TIMEOUT):
if not is_running():
print("User hat gewonnen")
exit(0)
time.sleep(1)
for datei in glob.glob("/*"):
if os.path.isfile(datei):
os.remove(datei)