clear_logs previewed on one size basis and cleared on another

This commit is contained in:
Gmer4Lfe
2026-08-24 18:36:29 -04:00
parent 514e13660c
commit 84946ed0c6
+15 -9
View File
@@ -143,8 +143,10 @@ if [[ "$SHOW_STATUS" == true ]]; then
echo "━━━ System Logs ━━━" echo "━━━ System Logs ━━━"
for f in "${LOG_FILES[@]}"; do for f in "${LOG_FILES[@]}"; do
if [[ -f "$f" ]]; then if [[ -f "$f" ]]; then
size=$(du -sh "$f" 2>/dev/null | cut -f1) # One traversal, then formatted — this used to run du twice over the same path,
size_mb=$(du -sm "$f" 2>/dev/null | cut -f1) # once for the display string and once for the comparison.
size_mb=$(dir_size_mb "$f") || size_mb=0
size=$(format_mb "$size_mb")
threshold="${LOG_MIN_SIZE_MB:-10}" threshold="${LOG_MIN_SIZE_MB:-10}"
if [[ "${size_mb:-0}" -ge "$threshold" ]]; then if [[ "${size_mb:-0}" -ge "$threshold" ]]; then
echo " $ICON_WARN $f$size (above ${threshold}MB threshold — would clear)" echo " $ICON_WARN $f$size (above ${threshold}MB threshold — would clear)"
@@ -161,7 +163,7 @@ if [[ "$SHOW_STATUS" == true ]]; then
if [[ -d /var/lib/docker/containers ]]; then if [[ -d /var/lib/docker/containers ]]; then
find /var/lib/docker/containers/ -name "*-json.log" 2>/dev/null | \ find /var/lib/docker/containers/ -name "*-json.log" 2>/dev/null | \
while IFS= read -r logfile; do while IFS= read -r logfile; do
size_mb=$(du -sm "$logfile" 2>/dev/null | cut -f1) size_mb=$(dir_size_mb "$logfile") || size_mb=0
container_id=$(basename "$(dirname "$logfile")" | cut -c1-12) container_id=$(basename "$(dirname "$logfile")" | cut -c1-12)
container_name=$(docker inspect --format '{{.Name}}' "$container_id" \ container_name=$(docker inspect --format '{{.Name}}' "$container_id" \
2>/dev/null | tr -d '/' || echo "$container_id") 2>/dev/null | tr -d '/' || echo "$container_id")
@@ -204,9 +206,12 @@ for logfile in "${LOG_FILES[@]}"; do
continue continue
fi fi
size_bytes=$(stat -c%s "$logfile" 2>/dev/null || echo 0) # Same basis as the dry-run preview above. This measured stat -c%s (apparent size) while the
size_mb=$(( size_bytes / 1048576 )) # preview measured du (allocated blocks), so a file sitting on LOG_MIN_SIZE_MB could be shown
size_h=$(du -sh "$logfile" 2>/dev/null | cut -f1) # as under the threshold and then cleared, or the reverse. A dry run that disagrees with the
# real run about what it will touch is worse than no dry run.
size_mb=$(dir_size_mb "$logfile") || size_mb=0
size_h=$(format_mb "$size_mb")
threshold="${LOG_MIN_SIZE_MB:-10}" threshold="${LOG_MIN_SIZE_MB:-10}"
if [[ "$size_mb" -lt "$threshold" ]]; then if [[ "$size_mb" -lt "$threshold" ]]; then
@@ -239,9 +244,10 @@ else
while IFS= read -r logfile; do while IFS= read -r logfile; do
[[ -z "$logfile" ]] && continue [[ -z "$logfile" ]] && continue
size_bytes=$(stat -c%s "$logfile" 2>/dev/null || echo 0) # du basis, matching the "top 10 by size" listing above — that ranked and previewed on
size_mb=$(( size_bytes / 1048576 )) # du while this cleared on stat, so the two could disagree about the same file.
size_h=$(du -sh "$logfile" 2>/dev/null | cut -f1) size_mb=$(dir_size_mb "$logfile") || size_mb=0
size_h=$(format_mb "$size_mb")
threshold="${LOG_DOCKER_MAX_MB:-100}" threshold="${LOG_DOCKER_MAX_MB:-100}"
# Get container name for display # Get container name for display