-
Notifications
You must be signed in to change notification settings - Fork 1
/
dump_steno.sh
63 lines (58 loc) · 1.27 KB
/
dump_steno.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
#!/bin/bash
#
# Aaron Eppert - 3/6/2019
#
# Dump a range of data from Stenographer
#
# Example: /dump_steno.sh -s "July 24 2018" -e "July 25 2018" -o /tmp -i 3600
#
USAGE="usage: dump_steno [-h] [-s <start timestamp> -e <end timestamp> -o <output directory> -i <seconds per pcap>]"
STENOREAD=/opt/stenographer/bin/stenoread
if [ "$#" -ne 8 ]; then
echo $USAGE
exit 1
fi
start=0
stop=0
outdir=""
interval=0
while getopts 'hs:e:o:i:' OPTION; do
case "$OPTION" in
h)
echo $USAGE
exit 1
;;
s)
start=$(date --date "$OPTARG" +%s)
if [ $? -ne 0 ]; then
echo "Error: start time is invalid"
exit 1
fi
;;
e)
stop=$(date --date "$OPTARG" +%s)
if [ $? -ne 0 ]; then
echo "Error: stop time is invalid"
exit 1
fi
;;
o)
outdir="$OPTARG"
;;
i)
interval=$OPTARG
;;
*)
echo $USAGE
exit 1
;;
esac
done
shift "$(($OPTIND -1))"
for t in $(seq ${start} 3600 ${stop}); do
n=$((${t}+${interval}))
i=$(date --date @${t} +'%Y-%m-%dT%H:%M:%SZ')
x=$(date --date @${n} +'%Y-%m-%dT%H:%M:%SZ')
fn=$(echo ${outdir}/${i}_${x}.pcap | sed s/\://g)
$STENOREAD after $i and before $x -w $fn
done