3 # Report on project disk use.
4 # Output can be sent as email to admin with -m
5 # Automatically runs with nice and ionice (if available)
7 # Usage: project-disk-use [-m] [top-n-only]
9 # With -m mail the report to $cfg_admin instead of sending it to stdout
11 # Shows total disk usage in K bytes for $cfg_reporoot
12 # The top-n-only (all if not given) repos are then listed by
13 # decreasing order of disk space.
15 # Note that any *.git directories that are found in $cfg_reporoot that are
16 # not listed in $cfg_chroot/etc/group ARE included and have a '!' suffix added.
20 datefmt
='%Y-%m-%d %H:%M:%S %z'
21 startdate
="$(date "+$datefmt")"
26 if [ "$1" = "-m" ]; then
32 command -v nice
> /dev
/null
&& hasnice
=1
34 command -v ionice
> /dev
/null
&& hasionice
=1
37 _cmd
="du -k -s \"$1\" | cut -f 1"
38 [ -n "$hasionice" ] && _cmd
="ionice -c 3 $_cmd"
39 [ -n "$hasnice" ] && _cmd
="nice -n 19 $_cmd"
43 projlist
="$(cut -d : -f 1 < "$cfg_chroot/etc
/group
")"
46 echo "$projlist" |
grep -q -e "^$1$"
52 while IFS
='' read -r proj
; do
56 is_listed_proj
"$proj" || x
='!'
57 usek
="$(get_use_k "$proj.git
")"
58 total
="$(( $total + $usek ))"
59 line
="$(printf '%8d\t%s%s\n*' "$usek" "$proj" "$x")"
61 results
="$results$line"
63 $(find . -type d -name '*.git' -print -prune)
66 enddate
="$(date "+$datefmt")"
68 [ -n "$mailresult" ] && domail
='mail -s "[$cfg_name] Project Disk Use Report" "$cfg_admin"'
71 Project Disk Use Report
72 =======================
74 Repository Root: $cfg_reporoot
75 Start Time: $startdate
77 Total Disk Use: $total (1024-byte blocks)
79 $(df -h "$cfg_reporoot")
82 if [ $# -lt 1 ] ||
[ $1 != "0" ]; then
84 message
="Individual Repository Use"
85 case "${1%%[!0-9]*}" in ?
*)
86 message
="Individual Repository Use (top $1)"
87 topn
="head -n ${1%%[!0-9]*}"
92 echo "$message" |
tr -c '\n' -
94 printf '%s' "$results" |
sort -k1,1nr
-k2,2 |
$topn