Skip to content

Commit 8e9ef80

Browse files
authored
Create backup-sum.awk
1 parent 8e94cb3 commit 8e9ef80

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

backup-sum.awk

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/awk
2+
# $SERVERNAME,$REALTIME,$SENTBYTESHR,$TOTALSIZEHR
3+
4+
BEGIN {
5+
totaltime=0
6+
totaltransf=0
7+
totalsize=0
8+
FS=","
9+
i=0
10+
time_m=0
11+
time_s=0
12+
}
13+
14+
{
15+
server[i]=$1
16+
realtime[i]=$2
17+
transfsize[i]=$3
18+
serversize[i]=$4
19+
totaltime=totaltime+realtime[i]
20+
totaltransf=totaltransf+transfsize[i]
21+
totalsize=totalsize+serversize[i]
22+
i++
23+
}
24+
25+
END {
26+
tth=human(totaltransf)
27+
tsobh=human(totalsize)
28+
tbt=hms(totaltime)
29+
print "Total transferred:",tth
30+
print "Total size of backups:",tsobh
31+
print "Total backup time:",tbt
32+
}
33+
34+
function human(x) {
35+
s=" B KiB MiB GiB TiB EiB PiB YiB ZiB"
36+
while (x>=1024 && length(s)>1)
37+
{x/=1024; s=substr(s,5)}
38+
s=substr(s,1,4)
39+
xf=(s==" B ")?"%5d ":"%8.2f"
40+
out1=sprintf( xf"%s", x, s)
41+
gsub(/^[ \t+]+/, "", out1) # remove leading space
42+
return sprintf( "%s", out1)
43+
}
44+
45+
function hms(s) {
46+
h=int(s/3600);
47+
s=s-(h*3600);
48+
m=int(s/60);
49+
s=s-(m*60);
50+
return sprintf("%d:%02d:%02d", h, m, s);
51+
}

0 commit comments

Comments
 (0)