Need to deal with the comma correctly if we are appending to a file

This commit is contained in:
Frank Breedijk 2016-06-14 10:36:57 +02:00
parent 701545dbb6
commit 3b1d8b6253

View File

@ -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\",