motd.sh: fix zfs recursive snapshot usage

This commit is contained in:
Alice Gaudon 2023-03-08 12:24:45 +01:00
parent 4ca796d515
commit 8748916cd7

View File

@ -97,10 +97,10 @@ if test $(command -v zfs); then
pcent=$(echo "($used/$ttlsize)*100" | bc -l | numfmt --format="%3.0f")
gfxsize=$(numfmt --to=iec --format="%9f" $ttlsize)
gfxused=$(numfmt --to=iec --format="%9f" $used)
usedsnaprecursive=$(zfs get usedbysnapshots -r "$name" -H -p -t filesystem -o value | awk '{s+=$1} END {printf "%.0f", s}')
usedsnappercent=$(echo "($usedsnaprecursive/$ttlsize)*100" | bc -l | numfmt --format="%3.0f")
usedsnaprecursive=$(zfs get usedbysnapshots -r "$name" -H -p -t filesystem -o value | tail -n+2 | awk '{s+=$1} END {printf "%.0f", s}')
usedsnappercent=$(echo "(($usedsnap + $usedsnaprecursive)/$ttlsize)*100" | bc -l | numfmt --format="%3.0f")
useddspercent=$(echo "($usedds/$ttlsize)*100" | bc -l | numfmt --format="%3.0f")
usedchildpercent=$(echo "($usedchild/$ttlsize)*100" | bc -l | numfmt --format="%3.0f")
usedchildpercent=$(echo "(($usedchild - $usedsnaprecursive)/$ttlsize)*100" | bc -l | numfmt --format="%3.0f")
DISKS+="$name $pcent% $gfxsize $gfxused $usedsnappercent $useddspercent $usedchildpercent x$compressratio\n"
done <<< $(zfs list -H -p -d 0 -o name,available,used,usedsnap,usedds,usedchild,compressratio)
fi