Files
2026-07-11 05:40:27 +02:00

35 lines
728 B
Bash

#!/bin/sh
MOUNT="/downloads"
OUTPUT="/html/disk.json"
update_disk() {
LINE=$(df -h "$MOUNT" 2>/dev/null | awk 'NR==2')
if [ -z "$LINE" ]; then
echo "ERROR: df failed for $MOUNT" >&2
return 1
fi
TOTAL=$(echo "$LINE" | awk '{print $2}')
USED=$(echo "$LINE" | awk '{print $3}')
AVAILABLE=$(echo "$LINE" | awk '{print $4}')
USE_PERCENT=$(echo "$LINE" | awk '{print $5}')
cat > "$OUTPUT" <<JSON
{
"total": "$TOTAL",
"used": "$USED",
"available": "$AVAILABLE",
"use_percent": "$USE_PERCENT",
"updated_at": "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
}
JSON
echo "disk.json updated: $USE_PERCENT used ($USED / $TOTAL)"
}
while true; do
update_disk || true
sleep 30
done