From 3b1d8b6253f81fe2dd1269030d63da4503650e1c Mon Sep 17 00:00:00 2001 From: Frank Breedijk Date: Tue, 14 Jun 2016 10:36:57 +0200 Subject: [PATCH] Need to deal with the comma correctly if we are appending to a file --- testssl.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/testssl.sh b/testssl.sh index 9588cc7..e99d6b0 100755 --- a/testssl.sh +++ b/testssl.sh @@ -455,7 +455,11 @@ strip_quote() { fileout_header() { if [[ $APPEND ]]; then - "$do_json" && [[ ! -f "$JSONFILE" ]] && printf "[\n" > "$JSONFILE" + if [[ -f "$JSONFILE" ]]; then + FIRST_FINDING=false # We need to insert a comma, because there is file content already + else + "$do_json" && printf "[\n" > "$JSONFILE" + fi "$do_csv" && [[ ! -f "CSVFILE" ]] && echo "\"id\",\"fqdn/ip\",\"port\",\"severity\",\"finding\"" > "$CSVFILE" else "$do_json" && printf "[\n" > "$JSONFILE" @@ -471,9 +475,8 @@ fileout() { # ID, SEVERITY, FINDING local finding=$(strip_lf "$(newline_to_spaces "$(strip_quote "$3")")") if "$do_json"; then - "$FIRST_FINDING" || echo "," >> $JSONFILE - echo -e " - { + "$FIRST_FINDING" || echo -n "," >> $JSONFILE + echo -e " { \"id\" : \"$1\", \"ip\" : \"$NODE/$NODEIP\", \"port\" : \"$PORT\",