-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup-sum.awk
More file actions
51 lines (46 loc) · 1 KB
/
backup-sum.awk
File metadata and controls
51 lines (46 loc) · 1 KB
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
#!/usr/bin/awk
# $SERVERNAME,$REALTIME,$SENTBYTESHR,$TOTALSIZEHR
BEGIN {
totaltime=0
totaltransf=0
totalsize=0
FS=","
i=0
time_m=0
time_s=0
}
{
server[i]=$1
realtime[i]=$2
transfsize[i]=$3
serversize[i]=$4
totaltime=totaltime+realtime[i]
totaltransf=totaltransf+transfsize[i]
totalsize=totalsize+serversize[i]
i++
}
END {
tth=human(totaltransf)
tsobh=human(totalsize)
tbt=hms(totaltime)
print "Total transferred:",tth
print "Total size of backups:",tsobh
print "Total backup time:",tbt
}
function human(x) {
s=" B KiB MiB GiB TiB EiB PiB YiB ZiB"
while (x>=1024 && length(s)>1)
{x/=1024; s=substr(s,5)}
s=substr(s,1,4)
xf=(s==" B ")?"%5d ":"%8.2f"
out1=sprintf( xf"%s", x, s)
gsub(/^[ \t+]+/, "", out1) # remove leading space
return sprintf( "%s", out1)
}
function hms(s) {
h=int(s/3600);
s=s-(h*3600);
m=int(s/60);
s=s-(m*60);
return sprintf("%d:%02d:%02d", h, m, s);
}