backup-disk-onoff in python

This commit is contained in:
2025-11-19 08:41:28 +01:00
parent df75c75fc1
commit 2e245eeefa
2 changed files with 51 additions and 0 deletions

13
.continue/rules/main.md Normal file
View File

@@ -0,0 +1,13 @@
# Project Architecture
This is a ansible project for a small network of hosts:
- Roles in `/roles`
- Inventory in `/inventory`
- Host definition in `site.xml`
## Coding Standards
- There are some scripts/files in other languages like python
- The project is managed in git.
- Follow the existing naming conventions: All ansible yaml files should have the ending .yaml

View File

@@ -0,0 +1,38 @@
import subprocess
import json
# Run the systemctl command and capture the output
try:
result = subprocess.run(
["systemctl", "list-units", "--type=automount", "--no-legend", "--output=json"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=True
)
except subprocess.CalledProcessError as e:
print(f"Error executing command: {e.stderr}")
exit(1)
# Parse the JSON output
try:
units = json.loads(result.stdout)
except json.JSONDecodeError as e:
print(f"Error parsing JSON: {e}")
exit(1)
# Filter units that are loaded, active, and sub: running
running_units = []
for unit in units:
if (
unit.get("load") == "loaded" and
unit.get("active") == "active" and
unit.get("sub") == "running" and
unit.get("unit", "").startswith("backup-")
):
running_units.append(unit)
# Output the results
print("Units with load: loaded, active: active, sub: running:")
for unit in running_units:
print(f" - {unit['unit']}: {unit['description']}")