-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathtcpdump
43 lines (35 loc) · 979 Bytes
/
tcpdump
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
#!/bin/bash
#
# lib/tcpdump
# Functions to start and stop a tcpdump
# Dependencies:
#
# - ``functions`` file
# ``stack.sh`` calls the entry points in this order:
#
# - start_tcpdump
# - stop_tcpdump
# Save trace setting
_XTRACE_TCPDUMP=$(set +o | grep xtrace)
set +o xtrace
TCPDUMP_OUTPUT=${TCPDUMP_OUTPUT:-$LOGDIR/tcpdump.pcap}
# e.g. for iscsi
# "-i any tcp port 3260"
TCPDUMP_ARGS=${TCPDUMP_ARGS:-""}
# start_tcpdump() - Start running processes
function start_tcpdump {
# Run a tcpdump with given arguments and save the packet capture
if is_service_enabled tcpdump; then
if [[ -z "${TCPDUMP_ARGS}" ]]; then
die $LINENO "The tcpdump service requires TCPDUMP_ARGS to be set"
fi
touch ${TCPDUMP_OUTPUT}
run_process tcpdump "/usr/sbin/tcpdump -w $TCPDUMP_OUTPUT $TCPDUMP_ARGS" root root
fi
}
# stop_tcpdump() stop tcpdump process
function stop_tcpdump {
stop_process tcpdump
}
# Restore xtrace
$_XTRACE_TCPDUMP