-
Notifications
You must be signed in to change notification settings - Fork 0
/
DATA__ReportBranchUsage.sh
85 lines (63 loc) · 2.28 KB
/
DATA__ReportBranchUsage.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
###########################################################################################
###
### $Id: DATA__ReportBranchUsage.sh,v 1.5 2022/08/17 19:09:19 root Exp $
###
### Script to generate report for selected partition, providing disk usage under each top-level directory on that partition.
###
###########################################################################################
doThisPart()
{
if [ "${DISKmount}" = "/" ] ; then excludeDirs="! -name proc ! -name run" ; fi
REPORT="${STRT}/${BASE}_${DISKlabel}.txt"
COM="find . -maxdepth 1 -xdev -type d ${excludeDirs} ! -name . -exec du --one-file-system -sh '{}' \; | sort -hr "
echo "\t Doing: ${COM} ..."
( cd ${DISKmount} ; eval ${COM} ) |
awk -v label="${DISKlabel}" '{ if( $1 == "0" ){
outVal=$1 ;
outUnt="" ;
}else{
n=length( $1 ) ;
outVal=substr( $1, 1, n-1 ) ;
outUnt=substr( $1, n ) ;
} ;
temp=substr( $2, 3 ) ;
printf("%8.1f %1s /%s/%s\n", outVal, outUnt, label, temp ) ;
}' >${REPORT}
ls -l ${REPORT}
}
###############################################################################################
###############################################################################################
doAll=0
if [ "$1" = "--all" ] ; then doAll=1 ; fi
BASE=`basename "$0" ".sh" `
TMP=/tmp/${BASE}.tmp
STRT=`pwd`
PartList="${TMP}.parts"
Devices__ReportDiskParts.sh 2>>/dev/null | grep -v 'swap' | grep -v 'Not_Mounted' | sort -r --key 3 >${PartList}
### Report Format:
#/dev/sdb1 ext4 DB001_F1 f56b6086-229d-4c17-8a5b-e68de1a4e73d Mounted /DB001_F1
#/dev/sdc3 ext4 DB003_F1 1a3ab410-2639-44aa-b0ca-72da4f8027e8 Not_Mounted /site/DB003_F1
#/dev/sda1 swap DB004_S1 22da1040-af94-4767-becf-aa9aa400f8f2 Enabled [SWAP]
#/dev/sdb3 swap DB001_S1 c37e53cd-5882-401c-8ba3-172531a082e9 Not_Enabled [SWAP_OFFLINE]
cat ${PartList} | awk '{ print $3, $6 }' |
while [ true ]
do
read DISKlabel DISKmount
if [ -z "${DISKlabel}" ] ; then echo "" ; exit 0 ; fi
if [ ${doAll} -eq 1 ]
then
doThisPart
else
echo "\n\t Perform disk usage scan on partition ${DISKlabel} ? [y|N] => \c" >&2
read doit <&2
if [ -z "${doit}" ] ; then doit="N" ; fi
case ${doit} in
y* | Y* ) doThisPart ;;
* ) ;;
esac
fi
done
exit 0
exit 0
exit 0