Created
June 1, 2023 15:00
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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