-
Notifications
You must be signed in to change notification settings - Fork 45
/
replay.sh
executable file
·98 lines (78 loc) · 2.01 KB
/
replay.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
#!/bin/bash
AUDIT_CSV=""
SERVER="127.0.0.1"
PORT="8053"
FAIL_ONLY=0
NO_WAIT=0
HELP=0
# parse options
while [ -n "$1" ]; do
case "$1" in
-s|--server) SERVER="$2"; shift;;
-p|--port) PORT="$2"; shift;;
-f|--fail-only) FAIL_ONLY=1;;
-n|--no-wait) NO_WAIT=1;;
-h|--help) HELP=1; break;;
-*)
echo "Invalid option: $1" >&2
exit 1
;;
*)
if [ "$AUDIT_CSV" = "" ]; then
AUDIT_CSV="$1"
else
echo "duplicate audit $1" >&2
exit 1
fi
;;
esac
shift;
done
help_doc() {
cat <<-EOF
Usage: $0 [-s <server>] [-p <port>] <audit_csv>
options:
-s | --server The server address (default: 127.0.0.1)
-p | --port The server port (default: 8053)
-f | --fail-only Only replay fails
-n | --no-wait Replay without sleep.
-h | --help display this help
EOF
exit 1
}
if [ $HELP -gt 0 ]; then
help_doc
fi
echo "#######################################"
echo "Input file: $AUDIT_CSV"
echo "Server address: $SERVER"
echo "Server port: $PORT"
if [ $FAIL_ONLY -gt 0 ]; then
echo "Filter: Only replay fails"
fi
echo "#######################################"
# exit 0
###################
FIRST_LINE=1
LAST_TIME=0
[ ! -f $AUDIT_CSV ] && { echo "$AUDIT_CSV file not found"; exit 99; }
while IFS=, read -r ID TIMESTAMP CLIENT NAME TYPE ELAPSED SPEED STATE RESULT
do
if [ $FIRST_LINE -eq 1 ]; then # skip header
FIRST_LINE=0
continue
fi
if [ $FAIL_ONLY -gt 0 ]; then
if [ "$STATE" = "success" ]; then
continue
fi
fi
if [ $NO_WAIT -eq 0 -a $LAST_TIME -gt 0 ]; then
INTERVAL=$(($TIMESTAMP-$LAST_TIME))
if [ $INTERVAL -gt 0 ]; then
sleep $INTERVAL
fi
fi
dig @$SERVER -p $PORT $TYPE $NAME
LAST_TIME=$TIMESTAMP
done < "$AUDIT_CSV"