Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- clear
- OUT="schnappi.qgroup.parsed"
- OUT2="schnappi.subvolume.parsed"
- OUT3="schnappi.schnapps.parsed"
- OUTFULL="schnappi.result"
- IN="schnappi.qgroup"
- IN2="schnappi.subvolume"
- IN3="schnappi.schnapps"
- FULLSIZE=0
- COMPACT=0
- for arg in "$@"
- do
- if [ $arg == "-f" ]; then
- FULLSIZE=1
- fi
- if [ $arg == "-c" ]; then
- COMPACT=1
- fi
- done
- read HEIGHT WIDTH <<<$(stty size)
- #exit 1
- trim() {
- local var="$*"
- echo "$var" | xargs
- }
- >$OUT
- >$OUT2
- >$OUT3
- >$OUTFULL
- btrfs quota enable /
- btrfs qgroup show / >$IN
- btrfs subvolume list / >$IN2
- schnapps list >$IN3
- OLDIFS=$IFS
- IFS=" "
- I=0;
- while read ids all size
- do
- I=$(($I+1))
- if (( $I>2 )); then
- IDPARTS=(${ids//\// })
- id=${IDPARTS[1]}
- echo -e "$id;$size" >>$OUT
- fi
- done < $IN
- IFS=$OLDIFS
- OLDIFS=$IFS
- IFS=" "
- I=0;
- while read non id non non non non non non schid
- do
- I=$(($I+1))
- if (( $I>0 )); then
- echo -e "$id;${schid//@/}" >>$OUT2
- fi
- done < $IN2
- IFS=$OLDIFS
- OLDIFS=$IFS
- IFS=" "
- I=0;
- while IFS='|' read schid type date description
- do
- I=$(($I+1))
- if (( $I>2 )); then
- # date=$(trim "$date")
- echo -e "$(trim "$schid");$(trim "$type");$(trim "$date");$(trim "$description")" >>$OUT3
- fi
- done < $IN3
- IFS=$OLDIFS
- # ---- show info ----
- unset qgroupsdata
- while IFS= read -r line
- do
- if [[ $(trim "$line") != "" ]]; then
- qgroupdata+=("$line")
- fi
- done < $OUT
- #echo -e "${qgroupdata[0]}"
- #echo -e "${qgroupdata[1]}"
- unset subvolumedata
- while IFS= read -r line
- do
- if [[ $(trim "$line") != "" ]]; then
- subvolumedata+=("$line")
- fi
- done < $OUT2
- #echo -e "${subvolumedata[0]}"
- #echo -e "${subvolumedata[1]}"
- unset schnappsdata
- while IFS= read -r line
- do
- if [[ $(trim "$line") != "" ]]; then
- schnappsdata+=("$line")
- fi
- done < $OUT3
- #echo -e "${schnappsdata[0]}"
- #echo -e "${schnappsdata[1]}"
- # --- print result ---
- findsch() {
- local haystack="$1"
- local needle="$2"
- unset schnappsdata
- while IFS= read -r line
- do
- if [[ $(trim "$line") != "" ]]; then
- schnappsdata+=("$line")
- fi
- done <"$haystack"
- for itemsch in "${schnappsdata[@]}"
- do
- IFS=';'
- read id type date comment <<<"$itemsch"
- IFS=' '
- read dd dt dz <<<"$date"
- IFS=':'
- read th tm ts <<<"$dt"
- if [ "$id" == "$needle" ]; then
- echo "$id;$type;$dd $th:$tm;$comment"
- fi
- done
- }
- findqg() {
- local haystack="$1"
- local needle="$2"
- unset data
- while IFS= read -r line
- do
- if [[ $(trim "$line") != "" ]]; then
- data+=("$line")
- fi
- done <"$haystack"
- for item in "${data[@]}"
- do
- IFS=';'
- read id size <<<"$item"
- if [ "$id" == "$needle" ]; then
- echo "$size"
- fi
- done
- }
- for item in "${subvolumedata[@]}"
- do
- IFS=';'
- read btrfs schnapps <<<"$item"
- result_schnapps="$(findsch "$OUT3" "$schnapps")"
- if [[ "$result_schnapps" != "" ]]; then
- result_qgroup="$(findqg "$OUT" "$btrfs")"
- echo "$result_schnapps;$result_qgroup" >>$OUTFULL
- fi
- done
- sort $OUTFULL >"$OUTFULL.sorted"
- mv $OUTFULL.sorted $OUTFULL
- unset data
- while IFS= read -r line
- do
- if [[ $(trim "$line") != "" ]]; then
- data+=("$line")
- fi
- done <"$OUTFULL"
- Sid=0
- Stype=0
- Sdate=0
- Scomment=0
- for item in "${data[@]}"
- do
- IFS=';'
- read id type date comment size <<<"$item"
- if [[ ${#id} -gt $Sid ]]; then Sid=${#id}; fi
- if [[ ${#type} -gt $Stype ]]; then Stype=${#type}; fi
- if [[ ${#date} -gt $Sdate ]]; then Sdate=${#date}; fi
- if [[ ${#comment} -gt $Scomment ]]; then Scomment=${#comment}; fi
- if [[ ${#size} -gt $Ssize ]]; then Ssize=${#size}; fi
- done
- Sfull=$(($Sid+$Stype+$Sdate+$Scomment+25))
- if [[ $WIDTH -gt $Sfull ]]; then
- FULLSIZE=1
- fi
- if [[ $COMPACT == 1 ]]; then
- FULLSIZE=0
- fi
- if [[ $FULLSIZE == 1 ]]; then
- printf "%${Sfull}s\n" |tr " " "-"
- printf "| %${Sid}s | %${Ssize}s | %-${Stype}s | %-${Sdate}s | %-${Scomment}s |\n" "ID" "Size" "Type" "Date" "Comment"
- printf "%${Sfull}s\n" |tr " " "-"
- for item in "${data[@]}"
- do
- IFS=';'
- read id type date comment size <<<"$item"
- printf "| %${Sid}s | %${Ssize}s | %-${Stype}s | %-${Sdate}s | %-${Scomment}s |\n" "$id" "$size" "$type" "$date" "$comment"
- done
- printf "%${Sfull}s\n" |tr " " "-"
- else
- Sfull=$(($Sid+$Stype+$Sdate+22))
- Sfullcommentcomplete=$(($Scomment+4))
- if [[ $Sfullcommentcomplete -gt $Sfull ]]; then
- Sfull=$Sfullcommentcomplete
- fi
- Sfullcomment=$(($Sfull-4))
- printf "%-${Sfull}s\n" |tr " " "-"
- printf "| %-${Sfullcomment}s |\n" $(printf "%${Sid}s | %${Ssize}s | %-${Stype}s | %-${Sdate}s" "ID" "Size" "Type" "Date")
- printf "| %-${Sfullcomment}s |\n" ""
- printf "| %-${Sfullcomment}s |\n" "Comment"
- printf "| %${Sfullcomment}s |\n" |tr " " "-"
- for item in "${data[@]}"
- do
- IFS=';'
- read id type date comment size <<<"$item"
- printf "| %-${Sfullcomment}s |\n" $(printf "%${Sid}s | %${Ssize}s | %-${Stype}s | %-${Sdate}s" "$id" "$size" "$type" "$date")
- printf "| %-${Sfullcomment}s |\n" ""
- printf "| %-${Sfullcomment}s |\n" "$comment"
- printf "| %${Sfullcomment}s |\n" |tr " " "-"
- done
- fi
- rm "$IN" "$IN2" "$IN3" "$OUTFULL" "$OUT" "$OUT2" "$OUT3"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement