add Final Infrastructure Setup
This commit is contained in:
commit
7733dde658
174 changed files with 204949 additions and 0 deletions
|
|
@ -0,0 +1,45 @@
|
|||
#!/bin/bash
|
||||
|
||||
TARGET_DIR="/local_testdata/test-destination"
|
||||
|
||||
THRESHOLD=60
|
||||
TARGET_USAGE=50
|
||||
|
||||
SLEEP_INTERVAL=2
|
||||
DELETE_BATCH=200
|
||||
SAFE_MINUTES=5
|
||||
|
||||
echo "[$(date)] Blackhole Monitor gestartet für $TARGET_DIR"
|
||||
|
||||
while true; do
|
||||
|
||||
CURRENT_USAGE=$(df -P "$TARGET_DIR" | awk 'NR==2 {print $5}' | tr -d '%')
|
||||
|
||||
if (( CURRENT_USAGE > THRESHOLD )); then
|
||||
echo "[$(date)] Disk usage ${CURRENT_USAGE}% -> starte Cleanup"
|
||||
|
||||
while (( CURRENT_USAGE > TARGET_USAGE )); do
|
||||
|
||||
find "$TARGET_DIR" \
|
||||
-type f \
|
||||
-mmin +$SAFE_MINUTES \
|
||||
-print0 \
|
||||
| head -z -n $DELETE_BATCH \
|
||||
| xargs -0 -r rm -f
|
||||
|
||||
CURRENT_USAGE=$(df -P "$TARGET_DIR" | awk 'NR==2 {print $5}' | tr -d '%')
|
||||
|
||||
echo "[$(date)] aktuelle Auslastung: ${CURRENT_USAGE}%"
|
||||
|
||||
if ! find "$TARGET_DIR" -type f -mmin +$SAFE_MINUTES | head -n 1 | grep -q .; then
|
||||
echo "[$(date)] Keine alten Dateien mehr zum Löschen"
|
||||
break
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
echo "[$(date)] Cleanup beendet"
|
||||
fi
|
||||
|
||||
sleep "$SLEEP_INTERVAL"
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue