Created
June 17, 2019 14:01
-
-
Save JensForstmann/2e7aab580de5bfb05edb2d724eeefc8a to your computer and use it in GitHub Desktop.
Get used user quotas from btrfs volume
This file contains hidden or 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 | |
| userList=$(cat /etc/passwd) | |
| volume=/volume1/ | |
| usedSpaceList="" | |
| IFS=$'\n' | |
| for user in $userList | |
| do | |
| userName=$(echo $user | cut -d : -f 1) | |
| userId=$(echo $user | cut -d : -f 3) | |
| usedSpace=$(btrfs usrquota show -an -u $userId $volume | cut -d " " -f 3 | awk '{s+=$1} END {printf "%.0f", s}') | |
| usedSpaceHumanReadable=$(echo $usedSpace | numfmt --to=iec) | |
| usedSpaceList=$(echo -e "$usedSpaceList\n$usedSpace\t$usedSpaceHumanReadable\t$userName") | |
| done | |
| echo "$usedSpaceList" | sort -n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment