arehbein has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/30311 )
Change subject: ttcn3-tcpdump*.sh: Log stderr separately to file ......................................................................
ttcn3-tcpdump*.sh: Log stderr separately to file
The old output is preserved, too, in order to ensure compatibility with expectations regarding legacy behavior.
Related: OS#5736
Change-Id: Ia92ff32c8ce09ab7805c5509837ec88fa4b864c5 --- M ttcn3-tcpdump-start.sh M ttcn3-tcpdump-stop.sh 2 files changed, 22 insertions(+), 1 deletion(-)
Approvals: Jenkins Builder: Verified msuraev: Looks good to me, but someone else must approve laforge: Looks good to me, but someone else must approve arehbein: Looks good to me, approved
diff --git a/ttcn3-tcpdump-start.sh b/ttcn3-tcpdump-start.sh index 8bba72f..aa42e62 100755 --- a/ttcn3-tcpdump-start.sh +++ b/ttcn3-tcpdump-start.sh @@ -71,9 +71,28 @@ PID=$! echo $PID > $PIDFILE_NETCAT
-$CMD -s 1500 -n -i any -w "$TTCN3_PCAP_PATH/$TESTCASE.pcap" >$TTCN3_PCAP_PATH/$TESTCASE.pcap.stdout 2>&1 & +CMD_OUTFILE=$TTCN3_PCAP_PATH/$TESTCASE.pcap.stdout +CMD_OUTFILE_ERR=$TTCN3_PCAP_PATH/$TESTCASE.pcap.stderr +FIFO=/tmp/cmderr +if ! [ -e $FIFO ]; then + mkfifo $FIFO +else + echo "Warning: Named pipe already exists: $FIFO" +fi + +# Log stderr to CMD_OUTFILE and a dedicated error log file +tee $CMD_OUTFILE < $FIFO > $CMD_OUTFILE_ERR & +CMD_STR="$CMD -s 1500 -n -i any -w "$TTCN3_PCAP_PATH/$TESTCASE.pcap" >$CMD_OUTFILE 2>$FIFO &" +eval $CMD_STR +# $CMD -s 1500 -n -i any -w "$TTCN3_PCAP_PATH/$TESTCASE.pcap" >$CMD_OUTFILE & PID=$! echo $PID > $PIDFILE_PCAP +if [ -f $CMD_OUTFILE_ERR ] && [ $(wc -l $CMD_OUTFILE_ERR | awk '{print $1}') -ne 0 ]; then + echo "Warnings or error messages from command:" >&2 + echo " $CMD_STR" >&2 + echo "Message:" >&2 + echo "$(cat $CMD_OUTFILE_ERR)" | sed 's/^/\t/' >&2 +fi
# Wait until packet dumper creates the pcap file and starts recording. # We generate some traffic until we see packet dumper catches it. diff --git a/ttcn3-tcpdump-stop.sh b/ttcn3-tcpdump-stop.sh index 6796612..829ed2b 100755 --- a/ttcn3-tcpdump-stop.sh +++ b/ttcn3-tcpdump-stop.sh @@ -2,6 +2,7 @@
PIDFILE_PCAP=/tmp/pcap.pid PIDFILE_NETCAT=/tmp/netcat.pid +FIFO=/tmp/cmderr TESTCASE=$1 VERDICT="$2"
@@ -68,5 +69,6 @@
kill_rm_pidfile "$PIDFILE_PCAP" kill_rm_pidfile "$PIDFILE_NETCAT" +rm $FIFO
gzip -f "$TTCN3_PCAP_PATH/$TESTCASE.pcap"