display scheduling method in -d (#205)

This commit is contained in:
Masoko
2025-03-26 20:26:44 +02:00
committed by GitHub
parent f475efbe98
commit e3d41e3320

View File

@@ -115,6 +115,27 @@ def check_rpi_power_status():
return "Error: " + str(e) return "Error: " + str(e)
def check_service_file_exists():
service_file_path = "/etc/systemd/system/rpi-mqtt-monitor.service"
return os.path.exists(service_file_path)
def check_crontab_entry(script_name="rpi-cpu1mqtt.py"):
try:
# Get the current user's crontab
result = subprocess.run(['crontab', '-l'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
# If the crontab command fails, it means there is no crontab for the user
if result.returncode != 0:
return False
# Check if the script name is in the crontab output
return script_name in result.stdout
except Exception as e:
print(f"Error checking crontab: {e}")
return False
def read_ext_sensors(): def read_ext_sensors():
""" """
here we read the external sensors here we read the external sensors
@@ -376,7 +397,13 @@ def print_measured_values(monitored_values):
if len(drive_temps) > 0: if len(drive_temps) > 0:
for device, temp in drive_temps.items(): for device, temp in drive_temps.items():
output += f" {device.capitalize()} Temp: {temp:.2f}°C\n" output += f" {device.capitalize()} Temp: {temp:.2f}°C\n"
output += "\n:: Scheduling\n "
if check_service_file_exists():
output += " Running as Service\n"
elif check_crontab_entry():
output += " Running as Cron Job\n"
output += """\n:: Installation directory :: {} output += """\n:: Installation directory :: {}
:: Release notes {}: :: Release notes {}: