Skip to content

Instantly share code, notes, and snippets.

@hypevhs
Forked from sling00/dfree
Last active February 3, 2022 07:51
Show Gist options
  • Save hypevhs/b3ec8652e5daaddd21b0c5eefba83d10 to your computer and use it in GitHub Desktop.
Save hypevhs/b3ec8652e5daaddd21b0c5eefba83d10 to your computer and use it in GitHub Desktop.
dfree for samba that treats ZFS as a special case
#!/usr/bin/env bash
# vim: set et ts=2 sw=2:
# changes: run through shellcheck, fixing several bugs
set -euo pipefail
HERE="$(realpath "$1")"
if findmnt --noheadings --output FSTYPE --target "$HERE" | grep -Pq '^zfs$'; then
echo "dfree: $HERE is zfs" >&2
USED_BYTES=$(zfs get -o value -Hp used "$HERE")
AVAIL_BYTES=$(zfs get -o value -Hp available "$HERE")
USED=$((USED_BYTES/1024))
AVAIL=$((AVAIL_BYTES/1024))
TOTAL=$((USED+AVAIL))
echo "$TOTAL $AVAIL"
else
echo "dfree: $HERE is NOT zfs" >&2
df -k --output=size,avail "$HERE" | tail -1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment