-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime-delta.sh
62 lines (55 loc) · 1.25 KB
/
time-delta.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
#!/bin/bash
#
# Time Delta
#
# Runs given arguments and prints the time spent on the execution.
#
# Usage:
# ./time-delta.sh $ARGUMENTS
#
# Hint:
# $ARGUMENTS can be any command including it's parameters as you'd type it into your shell
#
# Examples:
# ./time-delta.sh nmap -sP 192.168.178.1/24
# ./time-delta.sh rsync -avzr --stats --progress --ignore-existing /some/local/folder [email protected]:/some/remote/folder
timeDelta() {
# save start time
START=$(date +"%s")
# ececute all given arguments
$*
# save time after executing
END=$(date +"%s")
# calculate time difference
DELTA=$((END - START))
printf "_____________________\n"
printf "\nThe execution took:\n"
parseSeconds "$DELTA"
printf "\n_____________________"
}
parseSeconds () {
num=$1
min=0
hour=0
day=0
if((num>59));then
((sec=num%60))
((num=num/60))
if((num>59));then
((min=num%60))
((num=num/60))
if((num>23));then
((hour=num%24))
((day=num/24))
else
((hour=num))
fi
else
((min=num))
fi
else
((sec=num))
fi
echo "$day"d "$hour"h "$min"m "$sec"s
}
timeDelta "$*"