Created
June 13, 2023 01:21
-
-
Save mchangrh/5b7619f1dbb3a18a340ec7783beb7717 to your computer and use it in GitHub Desktop.
ZFS SMB dfree
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
#!/bin/bash | |
CUR_PATH=$(pwd) | |
function GET_ZPOOL { | |
arrIN=(${CUR_PATH//\// }) | |
echo "${arrIN[0]}" | |
} | |
ZPOOL=$(GET_ZPOOL) | |
ZFS_CHECK_OUTPUT=$(zfs get type "$ZPOOL" 2>&1 > /dev/null) > /dev/null | |
if [[ $ZFS_CHECK_OUTPUT == *dataset\ does\ not\ exist* ]] | |
then | |
IS_ZFS=false | |
else | |
IS_ZFS=true | |
fi | |
if [[ $IS_ZFS = false ]] | |
then | |
df "$CUR_PATH" | tail -1 | awk '{print $2" "$4}' | |
else | |
USED_SNAPSHOTS=$(($(zfs get -o value -Hp usedbysnapshots "$ZPOOL") / 1024)) > /dev/null | |
USED_DATSET=$(($(zfs get -o value -Hp usedbydataset "$ZPOOL") / 1024)) > /dev/null | |
USED_CHILDREN=$(($(zfs get -o value -Hp usedbychildren "$ZPOOL") / 1024)) > /dev/null | |
USED=$((USED_SNAPSHOTS + USED_DATSET + USED_CHILDREN)) | |
AVAIL=$(($(zfs get -o value -Hp available "$ZPOOL") / 1024)) > /dev/null | |
TOTAL=$((USED+AVAIL)) > /dev/null | |
echo $TOTAL $AVAIL | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment