Fixes to disk usage

This commit is contained in:
Alexandru-Victor Macocian
2025-10-30 18:02:51 +01:00
parent d6caac4a97
commit 4d9ba4ba9e
+11 -10
View File
@@ -22,27 +22,28 @@ for i in {1..6}; do
# Use process substitution instead of pipe to avoid subshell issues
if [[ "$OS_TYPE" == "macos" ]]; then
# macOS df format: Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on
# Mount points can have spaces, so we need to handle the full line
while IFS= read -r line; do
# Skip header line
if [[ "$line" =~ ^Filesystem ]]; then
# Skip pseudo-filesystems (map auto_home, map auto_nfs) and devfs
df 2>/dev/null | tail -n +2 | while IFS= read -r line; do
# Get the first field to check filesystem type
filesystem=$(echo "$line" | awk '{print $1}')
# Skip map entries and other pseudo-filesystems
if [[ "$filesystem" == "map" || "$filesystem" == "devfs" ]]; then
continue
fi
# Extract fields using awk (handles multi-word mount points)
filesystem=$(echo "$line" | awk '{print $1}')
# For valid filesystems, extract: blocks (col 2), used (col 3), mount point (col 9+)
blocks=$(echo "$line" | awk '{print $2}')
used=$(echo "$line" | awk '{print $3}')
# Mount point is everything from column 9 onwards
mount=$(echo "$line" | awk '{for(i=9;i<=NF;i++) printf "%s%s", $i, (i<NF?" ":""); print ""}')
# Skip entries with 0 blocks (pseudo filesystems) or filesystem starting with dash
if [[ -n "$mount" && -n "$used" && -n "$blocks" && "$blocks" != "0" && "$filesystem" != "-" ]]; then
# Skip entries with 0 blocks
if [[ -n "$mount" && -n "$used" && -n "$blocks" && "$blocks" != "0" ]]; then
used_bytes=$((used * 512))
total_bytes=$((blocks * 512))
echo "$timestamp $mount $used_bytes $total_bytes" >> "$LOGFILE"
fi
done < <(df 2>/dev/null)
done
else
# Linux df with --output flag
while read -r mount used total; do