-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgeneratesummary.sh
executable file
·123 lines (85 loc) · 2.56 KB
/
generatesummary.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env bash
SCRIPT=$(readlink -m $(type -p $0))
SCRIPTDIR=$(dirname $SCRIPT)
logdir=$SCRIPTDIR/_data/logdirsizes
IFS=/ read -ra _rootdir <<< "$SCRIPTDIR"
rootdir=${_rootdir[1]}
datestamp=$(date +"%Y%m%d")
depth=3
summarydir=$SCRIPTDIR/_data/logdirsummary/$datestamp
mkdir -p $summarydir
findprefix() {
echo $1 | sed 's,\/,_,g' | sed 's,_$,,' | sed 's,^_,,'
}
logfilename() {
local dir=$1
local depth=$2
local prefix=$(findprefix $dir)
# logfile with current datestamp might not exist
# local logfile=${prefix}-dirsizes-${depth}-${datestamp}.csv
# so list the logfiles and use the latest one
ls $logdir/${prefix}-dirsizes-${depth}*csv | tail -n 1
}
remote_server() {
IFS=":" read server remotepath <<< "$1"
if [ -n ${remotepath} ]
then
echo true
else
echo false
fi
}
# main function =======================
for path in $(cat $SCRIPTDIR/_config/dirs.txt)
do
IFS=":" read server directory <<< $path
if [ -z $directory ]
then
directory=$server
remote=false
else
remote=true
fi
# remove trailing slash from directory name
directory=${directory%/}
logfile=$(logfilename $directory $depth)
echo Using logfile $logfile
if [ $directory == /data/pnl ] || [ $directory == /data/pnlx ] || [ $directory == /rfanfs/pnl-zorro ]
then
_dirs="$directory $directory/home $directory/Collaborators $directory/projects"
elif [ $directory == /data/predict1 ]
then
_dirs="$directory $directory/data_from_nda $directory/data_from_nda_dev $directory/home"
fi
for subdir in $_dirs
do
prefix=$(findprefix $subdir)
if [ "$remote" = true ]
then
# remote directories
$SCRIPTDIR/size_sort.py $logfile $summarydir/${prefix}-${datestamp}.csv `ssh $server "ls -d $subdir/*/"`
else
# local directories
$SCRIPTDIR/size_sort.py $logfile $summarydir/${prefix}-${datestamp}.csv `ls -d $subdir/*/`
fi
done
done
# zip the summary folder
# copy the summary to a temp directory to avoid permission denied errors
tmpdir=$(mktemp -d)
dir_bak=`pwd`
cd $tmpdir
cp -a $summarydir .
summaryzip=${rootdir}_${datestamp}.zip
zip -r $summaryzip $datestamp/
# email the summary
from=tbillah$domain
for user in $@
do
echo "" | mailx -r $from -s "/$rootdir/ disk usage spreadsheets $datestamp" \
-a $summaryzip\
-- $user$domain
done
cd $dir_bak
rm -r $tmpdir