Skip to content

Instantly share code, notes, and snippets.

@snowfag
Created June 1, 2023 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snowfag/38fec65e37b3778fbd85698ab8feb596 to your computer and use it in GitHub Desktop.
Save snowfag/38fec65e37b3778fbd85698ab8feb596 to your computer and use it in GitHub Desktop.
A samba dfree script I wrote a while back for correctly reporting the total and free space on zfs pools and any other fs if not zfs (read: it doesn't break on non zfs filesystems)
#!/usr/bin/env zsh
maybe_pool="$(df ${1} | awk -F'[\t/ ]' 'END{print $1}')"
if (zfs list -Hp "${maybe_pool}" >/dev/null 2>&1); then
pool_name="$(zfs list -Hp "${maybe_pool}" | awk -F"[\t/]" '{print $1}')"
zpool list -Hp "${pool_name}" | cut -f 2-4 | read total used zpoolfree
realfree="$(zfs list -Hp "${pool_name}" | cut -f 3)"
python3 -c "import bigfloat; print(f'{int(bigfloat.div(${total}, 1024))} {int(bigfloat.div(${realfree}, 1024))}')"
else
df "${1}" | tail -1 | awk '{print $2" "$4}'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment