Files
webgui/emhttp/plugins/dynamix/scripts/disk_size
Tom Mortensen f9ec00b488 repo reorg
2023-06-02 12:49:33 -07:00

30 lines
774 B
Bash
Executable File

#!/bin/bash
# usage: disk_size <disk-name> <output-file>
# Creates an "ini" output file suitable for php parse_ini_function which describes
# the size of <user-share> takes up on the selected disk.
# Since this uses the 'du' command, could take awhile.
disk="$1"
output="/var/local/emhttp/$disk.$2"
total=0;
echo "Computing share usage for $disk..."
rm -f "$output"
function check {
folder="/mnt/$2/$1"
if [[ -e "$folder" ]] ; then
echo "calculating $1 usage..."
size=$(du -sb "$folder"|cut -f1)
echo "$1=$size" >>"$output"
total=$(($total + $size))
fi
}
while IFS=$'\n' read -r share; do
[[ -d $share ]] && check "$(basename "$share")" "$disk"
done <<< $(ls -vd /mnt/user/*)
echo "share.total=$total" >>"$output"
echo "total disk usage: $total"