shell function to make pcap name.
@@ -11,12 +11,18 @@ if [[ $FILTER =~ ^\'.*\'$ ]]; then
FILTER=${FILTER:1:${#FILTER}-2}
fi
+make_pcap_name() {
+ local id=$1
+ local dt=$(date '+%Y-%m-%d_%H_%M_%S')
+ echo trace_${id}_${dt}.pcap
+}
+
# if ITERS is non-negative then do the capture ITERS times
if [ $ITERS -gt "0" ]; then
COUNTER=0
while [ $COUNTER -lt $ITERS ]; do
- dt=$(date '+%Y-%m-%d_%H_%M_%S')
- tcpdump -ni $NIC --no-tcpudp-payload -w 'trace_'"$ID"'_'"$dt"'.pcap' $FILTER &
+ name=$(make_pcap_name $ID)
+ tcpdump -ni $NIC --no-tcpudp-payload -w $name $FILTER &
pid=$!
sleep $INTERVAL
kill $pid
@@ -26,8 +32,8 @@ if [ $ITERS -gt "0" ]; then
else # else do the capture until killed
while true
do
- dt=$(date '+%Y-%m-%d_%H_%M_%S')
- tcpdump -ni $NIC --no-tcpudp-payload -w 'trace_'"$ID"'_'"$dt"'.pcap' $FILTER &
+ name=$(make_pcap_name $ID)
+ tcpdump -ni $NIC --no-tcpudp-payload -w $name $FILTER &
pid=$!
sleep $INTERVAL
kill $pid
